PATH:
opt
/
alt
/
alt-nodejs20
/
root
/
usr
/
include
/
unicode
// © 2025 and later: Unicode, Inc. and others. // License & terms of use: https://www.unicode.org/copyright.html // utfstring.h // created: 2025jul18 Markus W. Scherer #ifndef __UTFSTRING_H__ #define __UTFSTRING_H__ #include "unicode/utypes.h" #if U_SHOW_CPLUSPLUS_API || U_SHOW_CPLUSPLUS_HEADER_API || !defined(UTYPES_H) #include "unicode/utf16.h" /** * \file * \brief C++ header-only API: C++ string helper functions. */ #ifndef U_HIDE_DRAFT_API namespace U_HEADER_ONLY_NAMESPACE { namespace utfstring { // Write code points to strings -------------------------------------------- *** #ifndef U_IN_DOXYGEN namespace prv { // This function, and the public wrappers, // want to be U_FORCE_INLINE but the gcc-debug-build-and-test CI check failed with // error: ‘always_inline’ function might not be inlinable [-Werror=attributes] template<typename StringClass, bool validate> inline StringClass &appendCodePoint(StringClass &s, uint32_t c) { using Unit = typename StringClass::value_type; if constexpr (sizeof(Unit) == 1) { // UTF-8: Similar to U8_APPEND(). if (c <= 0x7f) { s.push_back(static_cast<Unit>(c)); } else { Unit buf[4]; uint8_t len; if (c <= 0x7ff) { len = 2; buf[2] = (c >> 6) | 0xc0; } else { if (validate ? c < 0xd800 || (c < 0xe000 || c > 0x10ffff ? (c = 0xfffd, true) : c <= 0xffff) : c <= 0xffff) { len = 3; buf[1] = (c >> 12) | 0xe0; } else { len = 4; buf[0] = (c >> 18) | 0xf0; buf[1] = ((c >> 12) & 0x3f) | 0x80; } buf[2] = ((c >> 6) & 0x3f) | 0x80; } buf[3] = (c & 0x3f) | 0x80; s.append(buf + 4 - len, len); } } else if constexpr (sizeof(Unit) == 2) { // UTF-16: Similar to U16_APPEND(). if (validate ? c < 0xd800 || (c < 0xe000 || c > 0x10ffff ? (c = 0xfffd, true) : c <= 0xffff) : c <= 0xffff) { s.push_back(static_cast<Unit>(c)); } else { Unit buf[2] = { U16_LEAD(c), U16_TRAIL(c) }; s.append(buf, 2); } } else { // UTF-32 s.push_back(!validate || U_IS_SCALAR_VALUE(c) ? c : 0xfffd); } return s; } } // namespace prv #endif // U_IN_DOXYGEN #ifndef U_HIDE_DRAFT_API /** * Appends the code point to the string. * Appends the U+FFFD replacement character instead if c is not a scalar value. * See https://www.unicode.org/glossary/#unicode_scalar_value * * @tparam StringClass A version of std::basic_string (or a compatible type) * @param s The string to append to * @param c The code point to append * @return s * @draft ICU 78 * @see U_IS_SCALAR_VALUE */ template<typename StringClass> inline StringClass &appendOrFFFD(StringClass &s, UChar32 c) { return prv::appendCodePoint<StringClass, true>(s, c); } /** * Appends the code point to the string. * The code point must be a scalar value; otherwise the behavior is undefined. * See https://www.unicode.org/glossary/#unicode_scalar_value * * @tparam StringClass A version of std::basic_string (or a compatible type) * @param s The string to append to * @param c The code point to append (must be a scalar value) * @return s * @draft ICU 78 * @see U_IS_SCALAR_VALUE */ template<typename StringClass> inline StringClass &appendUnsafe(StringClass &s, UChar32 c) { return prv::appendCodePoint<StringClass, false>(s, c); } /** * Returns the code point as a string of code units. * Returns the U+FFFD replacement character instead if c is not a scalar value. * See https://www.unicode.org/glossary/#unicode_scalar_value * * @tparam StringClass A version of std::basic_string (or a compatible type) * @param c The code point * @return the string of c's code units * @draft ICU 78 * @see U_IS_SCALAR_VALUE */ template<typename StringClass> inline StringClass encodeOrFFFD(UChar32 c) { StringClass s; prv::appendCodePoint<StringClass, true>(s, c); return s; } /** * Returns the code point as a string of code units. * The code point must be a scalar value; otherwise the behavior is undefined. * See https://www.unicode.org/glossary/#unicode_scalar_value * * @tparam StringClass A version of std::basic_string (or a compatible type) * @param c The code point * @return the string of c's code units * @draft ICU 78 * @see U_IS_SCALAR_VALUE */ template<typename StringClass> inline StringClass encodeUnsafe(UChar32 c) { StringClass s; prv::appendCodePoint<StringClass, false>(s, c); return s; } #endif // U_HIDE_DRAFT_API } // namespace utfstring } // namespace U_HEADER_ONLY_NAMESPACE #endif // U_HIDE_DRAFT_API #endif // U_SHOW_CPLUSPLUS_API || U_SHOW_CPLUSPLUS_HEADER_API #endif // __UTFSTRING_H__
[+]
..
[-] localpointer.h
[edit]
[-] stringpiece.h
[edit]
[-] uenum.h
[edit]
[-] ureldatefmt.h
[edit]
[-] measure.h
[edit]
[-] numberrangeformatter.h
[edit]
[-] ucharstrie.h
[edit]
[-] rep.h
[edit]
[-] numfmt.h
[edit]
[-] ulistformatter.h
[edit]
[-] umachine.h
[edit]
[-] unum.h
[edit]
[-] simplenumberformatter.h
[edit]
[-] filteredbrk.h
[edit]
[-] umutablecptrie.h
[edit]
[-] unumberoptions.h
[edit]
[-] messageformat2_data_model_names.h
[edit]
[-] nounit.h
[edit]
[-] gender.h
[edit]
[-] stsearch.h
[edit]
[-] ufieldpositer.h
[edit]
[-] dtptngen.h
[edit]
[-] messageformat2.h
[edit]
[-] ucat.h
[edit]
[-] ustdio.h
[edit]
[-] rbtz.h
[edit]
[-] udata.h
[edit]
[-] unumberformatter.h
[edit]
[-] utf.h
[edit]
[-] tznames.h
[edit]
[-] timezone.h
[edit]
[-] region.h
[edit]
[-] formattednumber.h
[edit]
[-] curramt.h
[edit]
[-] bytestriebuilder.h
[edit]
[-] utfstring.h
[edit]
[-] tblcoll.h
[edit]
[-] dtrule.h
[edit]
[-] unifunct.h
[edit]
[-] uformattednumber.h
[edit]
[-] parseerr.h
[edit]
[-] std_string.h
[edit]
[-] messageformat2_data_model.h
[edit]
[-] ucol.h
[edit]
[-] platform.h
[edit]
[-] measunit.h
[edit]
[-] uscript.h
[edit]
[-] ucnvsel.h
[edit]
[-] unifilt.h
[edit]
[-] uformattable.h
[edit]
[-] uloc.h
[edit]
[-] udatpg.h
[edit]
[-] listformatter.h
[edit]
[-] tmutamt.h
[edit]
[-] numsys.h
[edit]
[-] utf8.h
[edit]
[-] ubidi.h
[edit]
[-] selfmt.h
[edit]
[-] uspoof.h
[edit]
[-] fieldpos.h
[edit]
[-] translit.h
[edit]
[-] rbbi.h
[edit]
[-] appendable.h
[edit]
[-] localematcher.h
[edit]
[-] basictz.h
[edit]
[-] usetiter.h
[edit]
[-] tzrule.h
[edit]
[-] currpinf.h
[edit]
[-] uregion.h
[edit]
[-] scientificnumberformatter.h
[edit]
[-] ucnv.h
[edit]
[-] ucasemap.h
[edit]
[-] unorm.h
[edit]
[-] utext.h
[edit]
[-] urename.h
[edit]
[-] dbbi.h
[edit]
[-] icudataver.h
[edit]
[-] idna.h
[edit]
[-] unistr.h
[edit]
[-] umisc.h
[edit]
[-] uidna.h
[edit]
[-] utypes.h
[edit]
[-] stringtriebuilder.h
[edit]
[-] ures.h
[edit]
[-] reldatefmt.h
[edit]
[-] messagepattern.h
[edit]
[-] utmscale.h
[edit]
[-] simpleformatter.h
[edit]
[-] uset.h
[edit]
[-] utf16.h
[edit]
[-] ustringtrie.h
[edit]
[-] udisplaycontext.h
[edit]
[-] resbund.h
[edit]
[-] uregex.h
[edit]
[-] ugender.h
[edit]
[-] locid.h
[edit]
[-] umsg.h
[edit]
[-] casemap.h
[edit]
[-] normalizer2.h
[edit]
[-] putil.h
[edit]
[-] normlzr.h
[edit]
[-] uldnames.h
[edit]
[-] ubiditransform.h
[edit]
[-] utfiterator.h
[edit]
[-] choicfmt.h
[edit]
[-] dtfmtsym.h
[edit]
[-] tmutfmt.h
[edit]
[-] utrace.h
[edit]
[-] ubrk.h
[edit]
[-] ulocdata.h
[edit]
[-] utf32.h
[edit]
[-] usimplenumberformatter.h
[edit]
[-] unimatch.h
[edit]
[-] tzfmt.h
[edit]
[-] edits.h
[edit]
[-] ulocale.h
[edit]
[-] uformattedvalue.h
[edit]
[-] uvernum.h
[edit]
[-] ucal.h
[edit]
[-] udateintervalformat.h
[edit]
[-] bytestream.h
[edit]
[-] ucharstriebuilder.h
[edit]
[-] tztrans.h
[edit]
[-] localebuilder.h
[edit]
[-] format.h
[edit]
[-] rbnf.h
[edit]
[-] ucsdet.h
[edit]
[-] urep.h
[edit]
[-] plurfmt.h
[edit]
[-] unumberrangeformatter.h
[edit]
[-] symtable.h
[edit]
[-] ulocbuilder.h
[edit]
[-] dcfmtsym.h
[edit]
[-] uconfig.h
[edit]
[-] locdspnm.h
[edit]
[-] utrans.h
[edit]
[-] uchar.h
[edit]
[-] messageformat2_formattable.h
[edit]
[-] uobject.h
[edit]
[-] udat.h
[edit]
[-] stringoptions.h
[edit]
[-] ushape.h
[edit]
[-] dtitvinf.h
[edit]
[-] messageformat2_arguments.h
[edit]
[-] currunit.h
[edit]
[-] parsepos.h
[edit]
[-] decimfmt.h
[edit]
[-] displayoptions.h
[edit]
[-] ucnv_cb.h
[edit]
[-] coleitr.h
[edit]
[-] ucurr.h
[edit]
[-] tmunit.h
[edit]
[-] messageformat2_function_registry.h
[edit]
[-] utf_old.h
[edit]
[-] chariter.h
[edit]
[-] ptypes.h
[edit]
[-] uiter.h
[edit]
[-] unorm2.h
[edit]
[-] alphaindex.h
[edit]
[-] uniset.h
[edit]
[-] measfmt.h
[edit]
[-] numberformatter.h
[edit]
[-] datefmt.h
[edit]
[-] simpletz.h
[edit]
[-] search.h
[edit]
[-] msgfmt.h
[edit]
[-] schriter.h
[edit]
[-] usprep.h
[edit]
[-] plurrule.h
[edit]
[-] brkiter.h
[edit]
[-] formattedvalue.h
[edit]
[-] compactdecimalformat.h
[edit]
[-] ucnv_err.h
[edit]
[-] enumset.h
[edit]
[-] calendar.h
[edit]
[-] ustring.h
[edit]
[-] fmtable.h
[edit]
[-] uversion.h
[edit]
[-] udisplayoptions.h
[edit]
[-] ucpmap.h
[edit]
[-] regex.h
[edit]
[-] upluralrules.h
[edit]
[-] usearch.h
[edit]
[-] ucoleitr.h
[edit]
[-] dtintrv.h
[edit]
[-] bytestrie.h
[edit]
[-] ucptrie.h
[edit]
[-] docmain.h
[edit]
[-] caniter.h
[edit]
[-] gregocal.h
[edit]
[-] unumsys.h
[edit]
[-] strenum.h
[edit]
[-] uchriter.h
[edit]
[-] dtitvfmt.h
[edit]
[-] smpdtfmt.h
[edit]
[-] unirepl.h
[edit]
[-] icuplug.h
[edit]
[-] vtzone.h
[edit]
[-] ustream.h
[edit]
[-] uclean.h
[edit]
[-] sortkey.h
[edit]
[-] errorcode.h
[edit]
[-] fpositer.h
[edit]
[-] char16ptr.h
[edit]
[-] coll.h
[edit]