示例#1
0
// native geoip_region_code(const ip[], result[], len);
static cell AMX_NATIVE_CALL amx_geoip_region_code(AMX *amx, cell *params)
{
	int length;
	int finalLength = 0;
	char code[12]; // This should be largely enough to hold xx-yyyy and more if needed.

	char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));

	const char *pathCountry[] = { "country", "iso_code", NULL };
	const char *countryCode = lookupString(ip, pathCountry, &length);

	if (countryCode)
	{
		finalLength = length + 1; // + 1 for dash.
		ke::SafeSprintf(code, finalLength + 1, "%s-", countryCode); // + EOS.

		const char *pathRegion[] = { "subdivisions", "0", "iso_code", NULL }; // First result.
		const char *regionCode = lookupString(ip, pathRegion, &length);

		if (regionCode)
		{
			finalLength += length;
			strncat(code, regionCode, length);
		}
		else
		{
			finalLength = 0;
		}
	}

	return MF_SetAmxString(amx, params[2], finalLength ? code : "", ke::Min(finalLength, params[3]));
}
示例#2
0
static StringObject* lookupInternedString(StringObject* strObj, bool isLiteral)
{
    StringObject* found;

    assert(strObj != NULL);
    u4 key = dvmComputeStringHash(strObj);
    dvmLockMutex(&gDvm.internLock);
    if (isLiteral) {
        /*
         * Check the literal table for a match.
         */
        StringObject* literal = lookupString(gDvm.literalStrings, key, strObj);
        if (literal != NULL) {
            /*
             * A match was found in the literal table, the easy case.
             */
            found = literal;
        } else {
            /*
             * There is no match in the literal table, check the
             * interned string table.
             */
            StringObject* interned = lookupString(gDvm.internedStrings, key, strObj);
            if (interned != NULL) {
                /*
                 * A match was found in the interned table.  Move the
                 * matching string to the literal table.
                 */
                dvmHashTableRemove(gDvm.internedStrings, key, interned);
                found = insertString(gDvm.literalStrings, key, interned);
                assert(found == interned);
            } else {
                /*
                 * No match in the literal table or the interned
                 * table.  Insert into the literal table.
                 */
                found = insertString(gDvm.literalStrings, key, strObj);
                assert(found == strObj);
            }
        }
    } else {
        /*
         * Check the literal table for a match.
         */
        found = lookupString(gDvm.literalStrings, key, strObj);
        if (found == NULL) {
            /*
             * No match was found in the literal table.  Insert into
             * the intern table if it does not already exist.
             */
            found = insertString(gDvm.internedStrings, key, strObj);
        }
    }
    assert(found != NULL);
    dvmUnlockMutex(&gDvm.internLock);
    return found;
}
示例#3
0
void SVGFontElement::registerLigaturesInGlyphCache(Vector<String>& ligatures)
{
    ASSERT(!ligatures.isEmpty());

    // Register each character of a ligature in the map, if not present.
    // Eg. If only a "fi" ligature is present, but not "f" and "i", the
    // GlyphPage will not contain any entries for "f" and "i", so the
    // SVGFont is not used to render the text "fi1234". Register an
    // empty SVGGlyph with the character, so the SVG Font will be used
    // to render the text. If someone tries to render "f2" the SVG Font
    // will not be able to find a glyph for "f", but handles the fallback
    // character substitution properly through glyphDataForCharacter().
    Vector<SVGGlyph> glyphs;
    for (auto& unicode : ligatures) {
        unsigned unicodeLength = unicode.length();
        ASSERT(unicodeLength > 1);

        for (unsigned i = 0; i < unicodeLength; ++i) {
            UChar character = unicode[i];
            String lookupString(&character, 1);
            m_glyphMap.collectGlyphsForString(lookupString, glyphs);
            if (!glyphs.isEmpty()) {
                glyphs.clear();
                continue;
            }

            // This glyph is never meant to be used for rendering, only as identifier as a part of a ligature.
            SVGGlyph newGlyphPart;
            newGlyphPart.isPartOfLigature = true;
            m_glyphMap.addGlyph(String(), lookupString, newGlyphPart);
        }
    }
}
示例#4
0
// native bool:geoip_code3_ex(const ip[], result[4]);
static cell AMX_NATIVE_CALL amx_geoip_code3_ex(AMX *amx, cell *params)
{
	int length;
	char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));

	const char *path[] = { "country", "iso_code", NULL };
	const char *code = lookupString(ip, path, &length);

	if (!code)
	{
		return 0;
	}

	for (size_t i = 0; i < ARRAYSIZE(GeoIPCountryCode); ++i)
	{
		if (!strncmp(code, GeoIPCountryCode[i], 2))
		{
			code = GeoIPCountryCode3[i];
			break;
		}
	}

	MF_SetAmxString(amx, params[2], code, 3);

	return 1;
}
示例#5
0
void APE_Tag::track(long& nr, long& count) const
{
	nr = 0; count = 0;
	wxString s = lookupString(wxT("TRACK"));
	if( s.IsEmpty() ) return;

	explodeNrAndCount(s, nr, count);
}
示例#6
0
void APE_Tag::disk(long& nr, long& count) const
{
	// see http://age.hobba.nl/audio/mirroredpages/apekey.html
	nr = 0; count = 0;
	wxString s = lookupString(wxT("MEDIA"));
	if( s.IsEmpty() ) return;

	explodeNrAndCount(s, nr, count);
}
示例#7
0
long APE_Tag::year() const
{
	wxString s = lookupString(wxT("YEAR"));
	if( s.IsEmpty() ) return 0;

	long l;
	if( !s.ToLong(&l) ) { l = 0; }
	return l;
}
示例#8
0
// native geoip_continent_name(const ip[], result[], len, id = -1);
static cell AMX_NATIVE_CALL amx_geoip_continent_name(AMX *amx, cell *params)
{
	int length;
	char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));

	const char *path[] = { "continent", "names", getLang(params[4]), NULL };
	const char *continent = lookupString(ip, path, &length);

	return MF_SetAmxStringUTF8Char(amx, params[2], continent ? continent : "", length, params[3]);
}
示例#9
0
// native geoip_code2(const ip[], ccode[3]);
// Deprecated.
static cell AMX_NATIVE_CALL amx_geoip_code2(AMX *amx, cell *params)
{
	int length;
	char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));

	const char *path[] = { "country", "iso_code", NULL };
	const char *code = lookupString(ip, path);

	return MF_SetAmxString(amx, params[2], code ? code : "error", 3);
}
示例#10
0
// native geoip_timezone(const ip[], result[], len);
static cell AMX_NATIVE_CALL amx_geoip_timezone(AMX *amx, cell *params)
{
	int length;
	char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));

	const char *path[] = { "location", "time_zone", NULL };
	const char *timezone = lookupString(ip, path, &length);

	return MF_SetAmxString(amx, params[2], timezone ? timezone : "", ke::Min(length, params[3]));
}
示例#11
0
// native geoip_region_name(const ip[], result[], len, id = -1);
static cell AMX_NATIVE_CALL amx_geoip_region_name(AMX *amx, cell *params)
{
	int length;
	char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));

	const char *path[] = { "subdivisions", "0", "names", getLang(params[4]), NULL }; // First result.
	const char *region = lookupString(ip, path, &length);

	return MF_SetAmxStringUTF8Char(amx, params[2], region ? region : "", length, params[3]);
}
示例#12
0
long APE_Tag::beatsPerMinute() const
{
	// I have not found anything standard-releated for this, so I use the same name as in ID3v2
	wxString s = lookupString(wxT("BPM"));
	if( s.IsEmpty() ) return 0;

	long l;
	if( !s.ToLong(&l) ) { l = 0; }
	return l;
}
示例#13
0
// native Continent:geoip_continent_code(const ip[], result[3] = "");
static cell AMX_NATIVE_CALL amx_geoip_continent_code(AMX *amx, cell *params)
{
	int length;
	char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));

	const char *path[] = { "continent", "code", NULL };
	const char *code = lookupString(ip, path, &length);

	MF_SetAmxString(amx, params[2], code ? code : "", code ? 2 : 0);

	return getContinentId(code);
}
示例#14
0
/*
 * Returns true if the object is a weak interned string.  Any string
 * interned by the user is weak.
 */
bool dvmIsWeakInternedString(StringObject* strObj)
{
    assert(strObj != NULL);
    if (gDvm.internedStrings == NULL) {
        return false;
    }
    dvmLockMutex(&gDvm.internLock);
    u4 key = dvmComputeStringHash(strObj);
    StringObject* found = lookupString(gDvm.internedStrings, key, strObj);
    dvmUnlockMutex(&gDvm.internLock);
    return found == strObj;
}
示例#15
0
// native geoip_country(const ip[], result[], len = 45);
// Deprecated.
static cell AMX_NATIVE_CALL amx_geoip_country(AMX *amx, cell *params)
{
	int length;
	char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));

	const char *path[] = { "country", "names", "en", NULL };
	const char *country = lookupString(ip, path, &length);

	if (!country)
	{
		return MF_SetAmxString(amx, params[2], "error", params[3]);
	}

	return MF_SetAmxStringUTF8Char(amx, params[2], country, length, params[3]);
}
示例#16
0
// native bool:geoip_code2_ex(const ip[], result[3]);
static cell AMX_NATIVE_CALL amx_geoip_code2_ex(AMX *amx, cell *params)
{
	int length;
	char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));

	const char *path[] = { "country", "iso_code", NULL };
	const char *code = lookupString(ip, path);

	if (!code)
	{
		return 0;
	}

	MF_SetAmxString(amx, params[2], code, 2);

	return 1;
}
示例#17
0
/*  7.7  */
SWmlToken * addTokenWithStr(SDocData *data,
                            UINT16    code,
                            PString   str,
                            ESite     site)
{
/* 
 * Append a new node for 'code' and 'str' to the list of WML tokens.
 * If str has never been seen before, create a new entry for it to remember,
 * otherwise treat the string entry as going to string table of the
 * output stream.
 * Note: site==STR_IN_TABLE only when it was called for unknown element
 *       or attribute.
 *---------------------------------------------------------------------------
 */
/* Data Structures */
  SWmlToken * _node;
  SWmlString * _strEntry = str ? lookupString(data,str) : 0; 

/* Code */

  if(site==STR_OPAQUE_DATE && str && STR_LEN(str)) {
      POOL_ALLOC(DOCPOOL, _strEntry);
      _strEntry->m_string = strXDup(str,DOCPOOL);
      _strEntry->m_site   = STR_OPAQUE_DATE;
      _strEntry->m_offset = ~0;

      SLL_INSERT(data->m_stringTable[0], _strEntry);
  }
  else if(_strEntry) {                      /* it has been seen */
      appendToTbl(data,_strEntry, 0);       /* 0: try to insert */
  }
  else if(str) {
      _strEntry = insertString(data,str);
      if(site==STR_IN_TABLE) {
          appendToTbl(data,_strEntry, 1);   /* 1: must insert   */
      }
  }
  /* If _strEntry is still NULL, it behaves as 'addToken'. */

  POOL_ALLOC(DOCPOOL, _node);
  _node->m_code     = code;
  _node->m_strEntry = _strEntry;
  FIFO_INSERT(data->m_tokenList, _node);
  
  return _node;
}
示例#18
0
bool SVGFontData::fillBMPGlyphs(SVGFontElement* fontElement, GlyphPage* pageToFill, unsigned offset, unsigned length, UChar* buffer, const SimpleFontData* fontData) const
{
    bool haveGlyphs = false;
    Vector<SVGGlyph> glyphs;
    for (unsigned i = 0; i < length; ++i) {
        String lookupString(buffer + i, 1);
        fontElement->collectGlyphsForString(lookupString, glyphs);
        if (glyphs.isEmpty()) {
            pageToFill->setGlyphDataForIndex(offset + i, 0, 0);
            continue;
        }

        // Associate entry in glyph page with first valid SVGGlyph.
        // If there are multiple valid ones, just take the first one. WidthIterator will take
        // care of matching to the correct glyph, if multiple ones are available, as that's
        // only possible within the context of a string (eg. arabic form matching).
        haveGlyphs = true;
        pageToFill->setGlyphDataForIndex(offset + i, glyphs.first().tableEntry, fontData);
        glyphs.clear();
    }

    return haveGlyphs;
}
示例#19
0
    void walk(const TextRun& run, bool isVerticalText, const String& language, int from, int to)
    {
        // Should hold true for SVG text, otherwhise sth. is wrong
        ASSERT(to - from == run.length());

        Vector<SVGGlyphIdentifier::ArabicForm> chars(charactersWithArabicForm(String(run.data(from), run.length()), run.rtl()));

        SVGGlyphIdentifier identifier;
        bool foundGlyph = false;
        int characterLookupRange;
        int endOfScanRange = to + m_walkerData.extraCharsAvailable;

        bool haveAltGlyph = false;
        SVGGlyphIdentifier altGlyphIdentifier;
        if (RenderObject* renderObject = run.referencingRenderObject()) {
            if (renderObject->element() && renderObject->element()->hasTagName(SVGNames::altGlyphTag)) {
                SVGGlyphElement* glyphElement = static_cast<SVGAltGlyphElement*>(renderObject->element())->glyphElement();
                if (glyphElement) {
                    haveAltGlyph = true;
                    altGlyphIdentifier = glyphElement->buildGlyphIdentifier();
                    altGlyphIdentifier.isValid = true;
                    altGlyphIdentifier.nameLength = to - from;
                }
            }
        }

        for (int i = from; i < to; ++i) {
            // If characterLookupRange is > 0, then the font defined ligatures (length of unicode property value > 1).
            // We have to check wheter the current character & the next character define a ligature. This needs to be
            // extended to the n-th next character (where n is 'characterLookupRange'), to check for any possible ligature.
            characterLookupRange = endOfScanRange - i;

            String lookupString(run.data(i), characterLookupRange);
            Vector<SVGGlyphIdentifier> glyphs;
            if (haveAltGlyph)
                glyphs.append(altGlyphIdentifier);
            else
                m_fontElement->getGlyphIdentifiersForString(lookupString, glyphs);

            Vector<SVGGlyphIdentifier>::iterator it = glyphs.begin();
            Vector<SVGGlyphIdentifier>::iterator end = glyphs.end();
            
            for (; it != end; ++it) {
                identifier = *it;
                if (identifier.isValid && isCompatibleGlyph(identifier, isVerticalText, language, chars, i, i + identifier.nameLength)) {
                    ASSERT(characterLookupRange > 0);
                    i += identifier.nameLength - 1;
                    m_walkerData.charsConsumed += identifier.nameLength;
                    m_walkerData.glyphName = identifier.glyphName;

                    foundGlyph = true;
                    SVGGlyphElement::inheritUnspecifiedAttributes(identifier, m_fontData);
                    break;
                }
            }

            if (!foundGlyph) {
                ++m_walkerData.charsConsumed;
                if (SVGMissingGlyphElement* element = m_fontElement->firstMissingGlyphElement()) {
                    // <missing-glyph> element support
                    identifier = SVGGlyphElement::buildGenericGlyphIdentifier(element);
                    SVGGlyphElement::inheritUnspecifiedAttributes(identifier, m_fontData);
                    identifier.isValid = true;
                } else {
                    // Fallback to system font fallback
                    TextRun subRun(run);
                    subRun.setText(subRun.data(i), 1);

                    (*m_walkerMissingGlyphCallback)(subRun, m_walkerData);
                    continue;
                }
            }

            if (!(*m_walkerCallback)(identifier, m_walkerData))
                break;

            foundGlyph = false;
        }
    }
QString DatabaseHandler::lookupMatricNumber(const QString &text)
{
    QString m_text = lookupString(text);
    return m_text;
}