Ejemplo n.º 1
0
static int32_t
unorm_iterate(UCharIterator * src, UBool forward,
              UChar * dest, int32_t destCapacity,
              UNormalizationMode mode, int32_t options,
              UBool doNormalize, UBool * pNeededToNormalize,
              UErrorCode * pErrorCode)
{
	const Normalizer2 * n2 = Normalizer2Factory::getInstance(mode, *pErrorCode);
	const UnicodeSet * uni32;
	if (options & UNORM_UNICODE_3_2)
	{
		uni32 = uniset_getUnicode32Instance(*pErrorCode);
	}
	else
	{
		uni32 = NULL; // unused
	}
	FilteredNormalizer2 fn2(*n2, *uni32);
	if (options & UNORM_UNICODE_3_2)
	{
		n2 = &fn2;
	}
	if (U_FAILURE(*pErrorCode))
	{
		return 0;
	}
	if (destCapacity < 0 || (dest == NULL && destCapacity > 0) ||
	    src == NULL
	   )
	{
		*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
		return 0;
	}

	if (pNeededToNormalize != NULL)
	{
		*pNeededToNormalize = FALSE;
	}
	if (!(forward ? src->hasNext(src) : src->hasPrevious(src)))
	{
		return u_terminateUChars(dest, destCapacity, 0, pErrorCode);
	}

	UnicodeString buffer;
	UChar32 c;
	if (forward)
	{
		/* get one character and ignore its properties */
		buffer.append(uiter_next32(src));
		/* get all following characters until we see a boundary */
		while ((c = uiter_next32(src)) >= 0)
		{
			if (n2->hasBoundaryBefore(c))
			{
				/* back out the latest movement to stop at the boundary */
				src->move(src, -U16_LENGTH(c), UITER_CURRENT);
				break;
			}
			else
			{
				buffer.append(c);
			}
		}
	}
	else
	{
		while ((c = uiter_previous32(src)) >= 0)
		{
			/* always write this character to the front of the buffer */
			buffer.insert(0, c);
			/* stop if this just-copied character is a boundary */
			if (n2->hasBoundaryBefore(c))
			{
				break;
			}
		}
	}

	UnicodeString destString(dest, 0, destCapacity);
	if (buffer.length() > 0 && doNormalize)
	{
		n2->normalize(buffer, destString, *pErrorCode).extract(dest, destCapacity, *pErrorCode);
		if (pNeededToNormalize != NULL && U_SUCCESS(*pErrorCode))
		{
			*pNeededToNormalize = destString != buffer;
		}
		return destString.length();
	}
	else
	{
		/* just copy the source characters */
		return buffer.extract(dest, destCapacity, *pErrorCode);
	}
}
Ejemplo n.º 2
0
D::D (bool p1)
{
  A **a = fn1 (mNewEntry);
  fn2 (p1, a);
}