diff options
author | neksard <neksard@yandex-team.ru> | 2022-02-10 16:45:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:23 +0300 |
commit | 8f7cf138264e0caa318144bf8a2c950e0b0a8593 (patch) | |
tree | 83bf5c8c8047c42d8475e6095df90ccdc3d1b57f /contrib/libs/icu/common/unistrappender.h | |
parent | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (diff) | |
download | ydb-8f7cf138264e0caa318144bf8a2c950e0b0a8593.tar.gz |
Restoring authorship annotation for <neksard@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/icu/common/unistrappender.h')
-rw-r--r-- | contrib/libs/icu/common/unistrappender.h | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/contrib/libs/icu/common/unistrappender.h b/contrib/libs/icu/common/unistrappender.h index 75fcb9e775..0890406d7a 100644 --- a/contrib/libs/icu/common/unistrappender.h +++ b/contrib/libs/icu/common/unistrappender.h @@ -1,90 +1,90 @@ // © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -****************************************************************************** -* Copyright (C) 2015, International Business Machines Corporation and -* others. All Rights Reserved. -****************************************************************************** -* -* File unistrappender.h -****************************************************************************** -*/ - -#ifndef __UNISTRAPPENDER_H__ -#define __UNISTRAPPENDER_H__ - -#include "unicode/unistr.h" -#include "unicode/uobject.h" -#include "unicode/utf16.h" -#include "unicode/utypes.h" -#include "cmemory.h" - -U_NAMESPACE_BEGIN - -/** - * An optimization for the slowness of calling UnicodeString::append() - * one character at a time in a loop. It stores appends in a buffer while - * never actually calling append on the unicode string unless the buffer - * fills up or is flushed. - * - * proper usage: - * { - * UnicodeStringAppender appender(astring); - * for (int32_t i = 0; i < 100; ++i) { - * appender.append((UChar) i); - * } - * // appender flushed automatically when it goes out of scope. - * } - */ -class UnicodeStringAppender : public UMemory { -public: - - /** - * dest is the UnicodeString being appended to. It must always - * exist while this instance exists. - */ - UnicodeStringAppender(UnicodeString &dest) : fDest(&dest), fIdx(0) { } - - inline void append(UChar x) { - if (fIdx == UPRV_LENGTHOF(fBuffer)) { - fDest->append(fBuffer, 0, fIdx); - fIdx = 0; - } - fBuffer[fIdx++] = x; - } - - inline void append(UChar32 x) { - if (fIdx >= UPRV_LENGTHOF(fBuffer) - 1) { - fDest->append(fBuffer, 0, fIdx); - fIdx = 0; - } - U16_APPEND_UNSAFE(fBuffer, fIdx, x); - } - - /** - * Ensures that all appended characters have been written out to dest. - */ - inline void flush() { - if (fIdx) { - fDest->append(fBuffer, 0, fIdx); - } - fIdx = 0; - } - - /** - * flush the buffer when we go out of scope. - */ - ~UnicodeStringAppender() { - flush(); - } -private: - UnicodeString *fDest; - int32_t fIdx; - UChar fBuffer[32]; - UnicodeStringAppender(const UnicodeStringAppender &other); - UnicodeStringAppender &operator=(const UnicodeStringAppender &other); -}; - -U_NAMESPACE_END - -#endif +// License & terms of use: http://www.unicode.org/copyright.html +/* +****************************************************************************** +* Copyright (C) 2015, International Business Machines Corporation and +* others. All Rights Reserved. +****************************************************************************** +* +* File unistrappender.h +****************************************************************************** +*/ + +#ifndef __UNISTRAPPENDER_H__ +#define __UNISTRAPPENDER_H__ + +#include "unicode/unistr.h" +#include "unicode/uobject.h" +#include "unicode/utf16.h" +#include "unicode/utypes.h" +#include "cmemory.h" + +U_NAMESPACE_BEGIN + +/** + * An optimization for the slowness of calling UnicodeString::append() + * one character at a time in a loop. It stores appends in a buffer while + * never actually calling append on the unicode string unless the buffer + * fills up or is flushed. + * + * proper usage: + * { + * UnicodeStringAppender appender(astring); + * for (int32_t i = 0; i < 100; ++i) { + * appender.append((UChar) i); + * } + * // appender flushed automatically when it goes out of scope. + * } + */ +class UnicodeStringAppender : public UMemory { +public: + + /** + * dest is the UnicodeString being appended to. It must always + * exist while this instance exists. + */ + UnicodeStringAppender(UnicodeString &dest) : fDest(&dest), fIdx(0) { } + + inline void append(UChar x) { + if (fIdx == UPRV_LENGTHOF(fBuffer)) { + fDest->append(fBuffer, 0, fIdx); + fIdx = 0; + } + fBuffer[fIdx++] = x; + } + + inline void append(UChar32 x) { + if (fIdx >= UPRV_LENGTHOF(fBuffer) - 1) { + fDest->append(fBuffer, 0, fIdx); + fIdx = 0; + } + U16_APPEND_UNSAFE(fBuffer, fIdx, x); + } + + /** + * Ensures that all appended characters have been written out to dest. + */ + inline void flush() { + if (fIdx) { + fDest->append(fBuffer, 0, fIdx); + } + fIdx = 0; + } + + /** + * flush the buffer when we go out of scope. + */ + ~UnicodeStringAppender() { + flush(); + } +private: + UnicodeString *fDest; + int32_t fIdx; + UChar fBuffer[32]; + UnicodeStringAppender(const UnicodeStringAppender &other); + UnicodeStringAppender &operator=(const UnicodeStringAppender &other); +}; + +U_NAMESPACE_END + +#endif |