예제 #1
0
// Transform strings (or substrings) prefixed with introducer (_charset) to ASCII equivalent.
void Parser::transformString(const char* start, unsigned length, string& dest)
{
    const static char HEX_DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                                      'A', 'B', 'C', 'D', 'E', 'F'
                                     };

    const unsigned fromBegin = start - lex.start;
    HalfStaticArray<char, 256> buffer;
    const char* pos = start;

    // We need only the "introduced" strings, in the bounds of "start" and "length" and in "pos"
    // order. Let collect them.

    SortedArray<StrMark> introducedMarks;

    GenericMap<NonPooled<IntlString*, StrMark> >::ConstAccessor accessor(&strMarks);
    for (bool found = accessor.getFirst(); found; found = accessor.getNext())
    {
        const StrMark& mark = accessor.current()->second;
        if (mark.introduced && mark.pos >= fromBegin && mark.pos < fromBegin + length)
            introducedMarks.add(mark);
    }

    for (size_t i = 0; i < introducedMarks.getCount(); ++i)
    {
        const StrMark& mark = introducedMarks[i];

        const char* s = lex.start + mark.pos;
        buffer.add(pos, s - pos);

        if (!isspace(UCHAR(pos[s - pos - 1])))
            buffer.add(' ');	// fix _charset'' becoming invalid syntax _charsetX''

        const size_t count = buffer.getCount();
        const size_t newSize = count + 2 + mark.str->getString().length() * 2 + 1;
        buffer.grow(newSize);
        char* p = buffer.begin() + count;

        *p++ = 'X';
        *p++ = '\'';

        const char* s2 = mark.str->getString().c_str();

        for (const char* end = s2 + mark.str->getString().length(); s2 < end; ++s2)
        {
            *p++ = HEX_DIGITS[UCHAR(*s2) >> 4];
            *p++ = HEX_DIGITS[UCHAR(*s2) & 0xF];
        }

        *p = '\'';
        fb_assert(p < buffer.begin() + newSize);

        pos = s + mark.length;
    }

    fb_assert(start + length - pos >= 0);
    buffer.add(pos, start + length - pos);

    dest.assign(buffer.begin(), MIN(string::max_length(), buffer.getCount()));
}
void releaseUpgradeTabs(IPluginModule* module)
{
	HalfStaticArray<UpgradeKey, 16> removeList;

	WriteLockGuard sync(mapLock, FB_FUNCTION);

	GenericMap<FunctionPair>::Accessor scan(&functionMap);

	if (scan.getFirst())
	{
		do
		{
			UpgradeKey& cur(scan.current()->first);

			if (cur.contains(module))
				removeList.add(cur);
		} while (scan.getNext());
	}

	for(unsigned int i = 0; i < removeList.getCount(); ++i)
		functionMap->remove(removeList[i]);
}