Logo Search packages:      
Sourcecode: icu version File versions  Download package

UChar * UnicodeString::getBuffer ( int32_t  minCapacity  ) 

Get a read/write pointer to the internal buffer. The buffer is guaranteed to be large enough for at least minCapacity UChars, writable, and is still owned by the UnicodeString object. Calls to getBuffer(minCapacity) must not be nested, and must be matched with calls to releaseBuffer(newLength). If the string buffer was read-only or shared, then it will be reallocated and copied.

An attempted nested call will return 0, and will not further modify the state of the UnicodeString object. It also returns 0 if the string is bogus.

The actual capacity of the string buffer may be larger than minCapacity. getCapacity() returns the actual capacity. For many operations, the full capacity should be used to avoid reallocations.

While the buffer is "open" between getBuffer(minCapacity) and releaseBuffer(newLength), the following applies:

  • The string length is set to 0.
  • Any read API call on the UnicodeString object will behave like on a 0-length string.
  • Any write API call on the UnicodeString object is disallowed and will have no effect.
  • You can read from and write to the returned buffer.
  • The previous string contents will still be in the buffer; if you want to use it, then you need to call length() before getBuffer(minCapacity). If the length() was greater than minCapacity, then any contents after minCapacity may be lost. The buffer contents is not NUL-terminated by getBuffer(). If length()<getCapacity() then you can terminate it by writing a NUL at index length().
  • You must call releaseBuffer(newLength) before and in order to return to normal UnicodeString operation.

minCapacity the minimum number of UChars that are to be available in the buffer, starting at the returned pointer; default to the current string capacity if minCapacity==-1
a writable pointer to the internal string buffer, or 0 if an error occurs (nested calls, out of memory)
See also:

getTerminatedBuffer() ICU 2.0

Definition at line 1480 of file unistr.cpp.

Referenced by UnicodeSet::applyPropertyAlias(), MessageFormat::autoQuoteApostrophe(), UnicodeSet::closeOver(), CollationElementIterator::CollationElementIterator(), RuleBasedCollator::compare(), Normalizer::compare(), RuleBasedCollator::construct(), UnicodeSet::containsAll(), UnicodeSet::containsNone(), IntlTestCollator::doTestVariant(), CanonicalIterator::extract(), ReplaceableGlue::extractBetween(), fromUTF32(), RuleBasedCollator::getCollationKey(), Locale::getDisplayCountry(), Locale::getDisplayLanguage(), Transliterator::getDisplayName(), Locale::getDisplayName(), Locale::getDisplayScript(), Locale::getDisplayVariant(), DecimalFormat::getEffectiveCurrency(), RuleBasedCollator::getSortKey(), ReplaceableGlue::handleReplaceBetween(), NameUnicodeTransliterator::handleTransliterate(), RegexMatcher::input(), izrule_getName(), StringSearch::operator=(), StringCharacterIterator::operator=(), UXMLParser::parseFile(), FieldsSet::parseFrom(), RegexPattern::pattern(), TransliteratorRegistry::put(), SearchIterator::SearchIterator(), StringEnumeration::setChars(), StringSearch::setPattern(), StringSearch::setText(), SearchIterator::setText(), CollationElementIterator::setText(), StringCharacterIterator::setText(), RuleBasedCollator::setVariableTop(), UnicodeSet::span(), UnicodeSet::spanBack(), StringCharacterIterator::StringCharacterIterator(), StringSearch::StringSearch(), CollationAPITest::TestCompare(), UnicodeStringTest::TestMiscellaneous(), UnicodeStringTest::TestPrefixAndSuffix(), CollationAPITest::TestSubclass(), TransliteratorTest::TestSurrogateCasing(), u_hasBinaryProperty(), udatpg_getAppendItemFormat(), udatpg_getAppendItemName(), udatpg_getDateTimeFormat(), udatpg_getDecimal(), udatpg_getPatternForSkeleton(), unorm_compare(), uregex_openC(), uspoof_getSkeleton(), utrans_getUnicodeID(), utrans_open(), vzone_getTZURL(), vzone_write(), vzone_writeFromStart(), vzone_writeSimple(), and zrule_getName().

  if(minCapacity>=-1 && cloneArrayIfNeeded(minCapacity)) {
    return getArrayStart();
  } else {
    return 0;

Generated by  Doxygen 1.6.0   Back to index