1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441 |
- /*
- **********************************************************************
- * Copyright (C) 1998-2010, International Business Machines
- * Corporation and others. All Rights Reserved.
- **********************************************************************
- *
- * File unistr.h
- *
- * Modification History:
- *
- * Date Name Description
- * 09/25/98 stephen Creation.
- * 11/11/98 stephen Changed per 11/9 code review.
- * 04/20/99 stephen Overhauled per 4/16 code review.
- * 11/18/99 aliu Made to inherit from Replaceable. Added method
- * handleReplaceBetween(); other methods unchanged.
- * 06/25/01 grhoten Remove dependency on iostream.
- ******************************************************************************
- */
- #ifndef UNISTR_H
- #define UNISTR_H
- /**
- * \file
- * \brief C++ API: Unicode String
- */
- #include "unicode/utypes.h"
- #include "unicode/rep.h"
- #include "unicode/std_string.h"
- #include "unicode/stringpiece.h"
- #include "unicode/bytestream.h"
- struct UConverter; // unicode/ucnv.h
- class StringThreadTest;
- #ifndef U_COMPARE_CODE_POINT_ORDER
- /* see also ustring.h and unorm.h */
- /**
- * Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc:
- * Compare strings in code point order instead of code unit order.
- * @stable ICU 2.2
- */
- #define U_COMPARE_CODE_POINT_ORDER 0x8000
- #endif
- #ifndef USTRING_H
- /**
- * \ingroup ustring_ustrlen
- */
- U_STABLE int32_t U_EXPORT2
- u_strlen(const UChar *s);
- #endif
- U_NAMESPACE_BEGIN
- class Locale; // unicode/locid.h
- class StringCharacterIterator;
- class BreakIterator; // unicode/brkiter.h
- /* The <iostream> include has been moved to unicode/ustream.h */
- /**
- * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
- * which constructs a Unicode string from an invariant-character char * string.
- * About invariant characters see utypes.h.
- * This constructor has no runtime dependency on conversion code and is
- * therefore recommended over ones taking a charset name string
- * (where the empty string "" indicates invariant-character conversion).
- *
- * @stable ICU 3.2
- */
- #define US_INV U_NAMESPACE_QUALIFIER UnicodeString::kInvariant
- /**
- * Unicode String literals in C++.
- * Dependent on the platform properties, different UnicodeString
- * constructors should be used to create a UnicodeString object from
- * a string literal.
- * The macros are defined for maximum performance.
- * They work only for strings that contain "invariant characters", i.e.,
- * only latin letters, digits, and some punctuation.
- * See utypes.h for details.
- *
- * The string parameter must be a C string literal.
- * The length of the string, not including the terminating
- * <code>NUL</code>, must be specified as a constant.
- * The U_STRING_DECL macro should be invoked exactly once for one
- * such string variable before it is used.
- * @stable ICU 2.0
- */
- #if defined(U_DECLARE_UTF16)
- # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
- #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
- # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)L ## cs, _length)
- #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
- # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)cs, _length)
- #else
- # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(cs, _length, US_INV)
- #endif
- /**
- * Unicode String literals in C++.
- * Dependent on the platform properties, different UnicodeString
- * constructors should be used to create a UnicodeString object from
- * a string literal.
- * The macros are defined for improved performance.
- * They work only for strings that contain "invariant characters", i.e.,
- * only latin letters, digits, and some punctuation.
- * See utypes.h for details.
- *
- * The string parameter must be a C string literal.
- * @stable ICU 2.0
- */
- #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
- /**
- * UnicodeString is a string class that stores Unicode characters directly and provides
- * similar functionality as the Java String and StringBuffer classes.
- * It is a concrete implementation of the abstract class Replaceable (for transliteration).
- *
- * The UnicodeString class is not suitable for subclassing.
- *
- * <p>For an overview of Unicode strings in C and C++ see the
- * <a href="http://icu-project.org/userguide/strings.html">User Guide Strings chapter</a>.</p>
- *
- * <p>In ICU, a Unicode string consists of 16-bit Unicode <em>code units</em>.
- * A Unicode character may be stored with either one code unit
- * (the most common case) or with a matched pair of special code units
- * ("surrogates"). The data type for code units is UChar.
- * For single-character handling, a Unicode character code <em>point</em> is a value
- * in the range 0..0x10ffff. ICU uses the UChar32 type for code points.</p>
- *
- * <p>Indexes and offsets into and lengths of strings always count code units, not code points.
- * This is the same as with multi-byte char* strings in traditional string handling.
- * Operations on partial strings typically do not test for code point boundaries.
- * If necessary, the user needs to take care of such boundaries by testing for the code unit
- * values or by using functions like
- * UnicodeString::getChar32Start() and UnicodeString::getChar32Limit()
- * (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).</p>
- *
- * UnicodeString methods are more lenient with regard to input parameter values
- * than other ICU APIs. In particular:
- * - If indexes are out of bounds for a UnicodeString object
- * (<0 or >length()) then they are "pinned" to the nearest boundary.
- * - If primitive string pointer values (e.g., const UChar * or char *)
- * for input strings are NULL, then those input string parameters are treated
- * as if they pointed to an empty string.
- * However, this is <em>not</em> the case for char * parameters for charset names
- * or other IDs.
- * - Most UnicodeString methods do not take a UErrorCode parameter because
- * there are usually very few opportunities for failure other than a shortage
- * of memory, error codes in low-level C++ string methods would be inconvenient,
- * and the error code as the last parameter (ICU convention) would prevent
- * the use of default parameter values.
- * Instead, such methods set the UnicodeString into a "bogus" state
- * (see isBogus()) if an error occurs.
- *
- * In string comparisons, two UnicodeString objects that are both "bogus"
- * compare equal (to be transitive and prevent endless loops in sorting),
- * and a "bogus" string compares less than any non-"bogus" one.
- *
- * Const UnicodeString methods are thread-safe. Multiple threads can use
- * const methods on the same UnicodeString object simultaneously,
- * but non-const methods must not be called concurrently (in multiple threads)
- * with any other (const or non-const) methods.
- *
- * Similarly, const UnicodeString & parameters are thread-safe.
- * One object may be passed in as such a parameter concurrently in multiple threads.
- * This includes the const UnicodeString & parameters for
- * copy construction, assignment, and cloning.
- *
- * <p>UnicodeString uses several storage methods.
- * String contents can be stored inside the UnicodeString object itself,
- * in an allocated and shared buffer, or in an outside buffer that is "aliased".
- * Most of this is done transparently, but careful aliasing in particular provides
- * significant performance improvements.
- * Also, the internal buffer is accessible via special functions.
- * For details see the
- * <a href="http://icu-project.org/userguide/strings.html">User Guide Strings chapter</a>.</p>
- *
- * @see utf.h
- * @see CharacterIterator
- * @stable ICU 2.0
- */
- class U_COMMON_API UnicodeString : public Replaceable
- {
- public:
- /**
- * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
- * which constructs a Unicode string from an invariant-character char * string.
- * Use the macro US_INV instead of the full qualification for this value.
- *
- * @see US_INV
- * @stable ICU 3.2
- */
- enum EInvariant {
- /**
- * @see EInvariant
- * @stable ICU 3.2
- */
- kInvariant
- };
- //========================================
- // Read-only operations
- //========================================
- /* Comparison - bitwise only - for international comparison use collation */
- /**
- * Equality operator. Performs only bitwise comparison.
- * @param text The UnicodeString to compare to this one.
- * @return TRUE if <TT>text</TT> contains the same characters as this one,
- * FALSE otherwise.
- * @stable ICU 2.0
- */
- inline UBool operator== (const UnicodeString& text) const;
- /**
- * Inequality operator. Performs only bitwise comparison.
- * @param text The UnicodeString to compare to this one.
- * @return FALSE if <TT>text</TT> contains the same characters as this one,
- * TRUE otherwise.
- * @stable ICU 2.0
- */
- inline UBool operator!= (const UnicodeString& text) const;
- /**
- * Greater than operator. Performs only bitwise comparison.
- * @param text The UnicodeString to compare to this one.
- * @return TRUE if the characters in this are bitwise
- * greater than the characters in <code>text</code>, FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool operator> (const UnicodeString& text) const;
- /**
- * Less than operator. Performs only bitwise comparison.
- * @param text The UnicodeString to compare to this one.
- * @return TRUE if the characters in this are bitwise
- * less than the characters in <code>text</code>, FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool operator< (const UnicodeString& text) const;
- /**
- * Greater than or equal operator. Performs only bitwise comparison.
- * @param text The UnicodeString to compare to this one.
- * @return TRUE if the characters in this are bitwise
- * greater than or equal to the characters in <code>text</code>, FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool operator>= (const UnicodeString& text) const;
- /**
- * Less than or equal operator. Performs only bitwise comparison.
- * @param text The UnicodeString to compare to this one.
- * @return TRUE if the characters in this are bitwise
- * less than or equal to the characters in <code>text</code>, FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool operator<= (const UnicodeString& text) const;
- /**
- * Compare the characters bitwise in this UnicodeString to
- * the characters in <code>text</code>.
- * @param text The UnicodeString to compare to this one.
- * @return The result of bitwise character comparison: 0 if this
- * contains the same characters as <code>text</code>, -1 if the characters in
- * this are bitwise less than the characters in <code>text</code>, +1 if the
- * characters in this are bitwise greater than the characters
- * in <code>text</code>.
- * @stable ICU 2.0
- */
- inline int8_t compare(const UnicodeString& text) const;
- /**
- * Compare the characters bitwise in the range
- * [<TT>start</TT>, <TT>start + length</TT>) with the characters
- * in <TT>text</TT>
- * @param start the offset at which the compare operation begins
- * @param length the number of characters of text to compare.
- * @param text the other text to be compared against this string.
- * @return The result of bitwise character comparison: 0 if this
- * contains the same characters as <code>text</code>, -1 if the characters in
- * this are bitwise less than the characters in <code>text</code>, +1 if the
- * characters in this are bitwise greater than the characters
- * in <code>text</code>.
- * @stable ICU 2.0
- */
- inline int8_t compare(int32_t start,
- int32_t length,
- const UnicodeString& text) const;
- /**
- * Compare the characters bitwise in the range
- * [<TT>start</TT>, <TT>start + length</TT>) with the characters
- * in <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
- * @param start the offset at which the compare operation begins
- * @param length the number of characters in this to compare.
- * @param srcText the text to be compared
- * @param srcStart the offset into <TT>srcText</TT> to start comparison
- * @param srcLength the number of characters in <TT>src</TT> to compare
- * @return The result of bitwise character comparison: 0 if this
- * contains the same characters as <code>srcText</code>, -1 if the characters in
- * this are bitwise less than the characters in <code>srcText</code>, +1 if the
- * characters in this are bitwise greater than the characters
- * in <code>srcText</code>.
- * @stable ICU 2.0
- */
- inline int8_t compare(int32_t start,
- int32_t length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const;
- /**
- * Compare the characters bitwise in this UnicodeString with the first
- * <TT>srcLength</TT> characters in <TT>srcChars</TT>.
- * @param srcChars The characters to compare to this UnicodeString.
- * @param srcLength the number of characters in <TT>srcChars</TT> to compare
- * @return The result of bitwise character comparison: 0 if this
- * contains the same characters as <code>srcChars</code>, -1 if the characters in
- * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
- * characters in this are bitwise greater than the characters
- * in <code>srcChars</code>.
- * @stable ICU 2.0
- */
- inline int8_t compare(const UChar *srcChars,
- int32_t srcLength) const;
- /**
- * Compare the characters bitwise in the range
- * [<TT>start</TT>, <TT>start + length</TT>) with the first
- * <TT>length</TT> characters in <TT>srcChars</TT>
- * @param start the offset at which the compare operation begins
- * @param length the number of characters to compare.
- * @param srcChars the characters to be compared
- * @return The result of bitwise character comparison: 0 if this
- * contains the same characters as <code>srcChars</code>, -1 if the characters in
- * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
- * characters in this are bitwise greater than the characters
- * in <code>srcChars</code>.
- * @stable ICU 2.0
- */
- inline int8_t compare(int32_t start,
- int32_t length,
- const UChar *srcChars) const;
- /**
- * Compare the characters bitwise in the range
- * [<TT>start</TT>, <TT>start + length</TT>) with the characters
- * in <TT>srcChars</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
- * @param start the offset at which the compare operation begins
- * @param length the number of characters in this to compare
- * @param srcChars the characters to be compared
- * @param srcStart the offset into <TT>srcChars</TT> to start comparison
- * @param srcLength the number of characters in <TT>srcChars</TT> to compare
- * @return The result of bitwise character comparison: 0 if this
- * contains the same characters as <code>srcChars</code>, -1 if the characters in
- * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
- * characters in this are bitwise greater than the characters
- * in <code>srcChars</code>.
- * @stable ICU 2.0
- */
- inline int8_t compare(int32_t start,
- int32_t length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const;
- /**
- * Compare the characters bitwise in the range
- * [<TT>start</TT>, <TT>limit</TT>) with the characters
- * in <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcLimit</TT>).
- * @param start the offset at which the compare operation begins
- * @param limit the offset immediately following the compare operation
- * @param srcText the text to be compared
- * @param srcStart the offset into <TT>srcText</TT> to start comparison
- * @param srcLimit the offset into <TT>srcText</TT> to limit comparison
- * @return The result of bitwise character comparison: 0 if this
- * contains the same characters as <code>srcText</code>, -1 if the characters in
- * this are bitwise less than the characters in <code>srcText</code>, +1 if the
- * characters in this are bitwise greater than the characters
- * in <code>srcText</code>.
- * @stable ICU 2.0
- */
- inline int8_t compareBetween(int32_t start,
- int32_t limit,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLimit) const;
- /**
- * Compare two Unicode strings in code point order.
- * The result may be different from the results of compare(), operator<, etc.
- * if supplementary characters are present:
- *
- * In UTF-16, supplementary characters (with code points U+10000 and above) are
- * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
- * which means that they compare as less than some other BMP characters like U+feff.
- * This function compares Unicode strings in code point order.
- * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
- *
- * @param text Another string to compare this one to.
- * @return a negative/zero/positive integer corresponding to whether
- * this string is less than/equal to/greater than the second one
- * in code point order
- * @stable ICU 2.0
- */
- inline int8_t compareCodePointOrder(const UnicodeString& text) const;
- /**
- * Compare two Unicode strings in code point order.
- * The result may be different from the results of compare(), operator<, etc.
- * if supplementary characters are present:
- *
- * In UTF-16, supplementary characters (with code points U+10000 and above) are
- * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
- * which means that they compare as less than some other BMP characters like U+feff.
- * This function compares Unicode strings in code point order.
- * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param length The number of code units from this string to compare.
- * @param srcText Another string to compare this one to.
- * @return a negative/zero/positive integer corresponding to whether
- * this string is less than/equal to/greater than the second one
- * in code point order
- * @stable ICU 2.0
- */
- inline int8_t compareCodePointOrder(int32_t start,
- int32_t length,
- const UnicodeString& srcText) const;
- /**
- * Compare two Unicode strings in code point order.
- * The result may be different from the results of compare(), operator<, etc.
- * if supplementary characters are present:
- *
- * In UTF-16, supplementary characters (with code points U+10000 and above) are
- * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
- * which means that they compare as less than some other BMP characters like U+feff.
- * This function compares Unicode strings in code point order.
- * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param length The number of code units from this string to compare.
- * @param srcText Another string to compare this one to.
- * @param srcStart The start offset in that string at which the compare operation begins.
- * @param srcLength The number of code units from that string to compare.
- * @return a negative/zero/positive integer corresponding to whether
- * this string is less than/equal to/greater than the second one
- * in code point order
- * @stable ICU 2.0
- */
- inline int8_t compareCodePointOrder(int32_t start,
- int32_t length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const;
- /**
- * Compare two Unicode strings in code point order.
- * The result may be different from the results of compare(), operator<, etc.
- * if supplementary characters are present:
- *
- * In UTF-16, supplementary characters (with code points U+10000 and above) are
- * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
- * which means that they compare as less than some other BMP characters like U+feff.
- * This function compares Unicode strings in code point order.
- * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
- *
- * @param srcChars A pointer to another string to compare this one to.
- * @param srcLength The number of code units from that string to compare.
- * @return a negative/zero/positive integer corresponding to whether
- * this string is less than/equal to/greater than the second one
- * in code point order
- * @stable ICU 2.0
- */
- inline int8_t compareCodePointOrder(const UChar *srcChars,
- int32_t srcLength) const;
- /**
- * Compare two Unicode strings in code point order.
- * The result may be different from the results of compare(), operator<, etc.
- * if supplementary characters are present:
- *
- * In UTF-16, supplementary characters (with code points U+10000 and above) are
- * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
- * which means that they compare as less than some other BMP characters like U+feff.
- * This function compares Unicode strings in code point order.
- * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param length The number of code units from this string to compare.
- * @param srcChars A pointer to another string to compare this one to.
- * @return a negative/zero/positive integer corresponding to whether
- * this string is less than/equal to/greater than the second one
- * in code point order
- * @stable ICU 2.0
- */
- inline int8_t compareCodePointOrder(int32_t start,
- int32_t length,
- const UChar *srcChars) const;
- /**
- * Compare two Unicode strings in code point order.
- * The result may be different from the results of compare(), operator<, etc.
- * if supplementary characters are present:
- *
- * In UTF-16, supplementary characters (with code points U+10000 and above) are
- * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
- * which means that they compare as less than some other BMP characters like U+feff.
- * This function compares Unicode strings in code point order.
- * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param length The number of code units from this string to compare.
- * @param srcChars A pointer to another string to compare this one to.
- * @param srcStart The start offset in that string at which the compare operation begins.
- * @param srcLength The number of code units from that string to compare.
- * @return a negative/zero/positive integer corresponding to whether
- * this string is less than/equal to/greater than the second one
- * in code point order
- * @stable ICU 2.0
- */
- inline int8_t compareCodePointOrder(int32_t start,
- int32_t length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const;
- /**
- * Compare two Unicode strings in code point order.
- * The result may be different from the results of compare(), operator<, etc.
- * if supplementary characters are present:
- *
- * In UTF-16, supplementary characters (with code points U+10000 and above) are
- * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
- * which means that they compare as less than some other BMP characters like U+feff.
- * This function compares Unicode strings in code point order.
- * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param limit The offset after the last code unit from this string to compare.
- * @param srcText Another string to compare this one to.
- * @param srcStart The start offset in that string at which the compare operation begins.
- * @param srcLimit The offset after the last code unit from that string to compare.
- * @return a negative/zero/positive integer corresponding to whether
- * this string is less than/equal to/greater than the second one
- * in code point order
- * @stable ICU 2.0
- */
- inline int8_t compareCodePointOrderBetween(int32_t start,
- int32_t limit,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLimit) const;
- /**
- * Compare two strings case-insensitively using full case folding.
- * This is equivalent to this->foldCase(options).compare(text.foldCase(options)).
- *
- * @param text Another string to compare this one to.
- * @param options A bit set of options:
- * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
- * Comparison in code unit order with default case folding.
- *
- * - U_COMPARE_CODE_POINT_ORDER
- * Set to choose code point order instead of code unit order
- * (see u_strCompare for details).
- *
- * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
- *
- * @return A negative, zero, or positive integer indicating the comparison result.
- * @stable ICU 2.0
- */
- inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
- /**
- * Compare two strings case-insensitively using full case folding.
- * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param length The number of code units from this string to compare.
- * @param srcText Another string to compare this one to.
- * @param options A bit set of options:
- * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
- * Comparison in code unit order with default case folding.
- *
- * - U_COMPARE_CODE_POINT_ORDER
- * Set to choose code point order instead of code unit order
- * (see u_strCompare for details).
- *
- * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
- *
- * @return A negative, zero, or positive integer indicating the comparison result.
- * @stable ICU 2.0
- */
- inline int8_t caseCompare(int32_t start,
- int32_t length,
- const UnicodeString& srcText,
- uint32_t options) const;
- /**
- * Compare two strings case-insensitively using full case folding.
- * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param length The number of code units from this string to compare.
- * @param srcText Another string to compare this one to.
- * @param srcStart The start offset in that string at which the compare operation begins.
- * @param srcLength The number of code units from that string to compare.
- * @param options A bit set of options:
- * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
- * Comparison in code unit order with default case folding.
- *
- * - U_COMPARE_CODE_POINT_ORDER
- * Set to choose code point order instead of code unit order
- * (see u_strCompare for details).
- *
- * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
- *
- * @return A negative, zero, or positive integer indicating the comparison result.
- * @stable ICU 2.0
- */
- inline int8_t caseCompare(int32_t start,
- int32_t length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength,
- uint32_t options) const;
- /**
- * Compare two strings case-insensitively using full case folding.
- * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
- *
- * @param srcChars A pointer to another string to compare this one to.
- * @param srcLength The number of code units from that string to compare.
- * @param options A bit set of options:
- * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
- * Comparison in code unit order with default case folding.
- *
- * - U_COMPARE_CODE_POINT_ORDER
- * Set to choose code point order instead of code unit order
- * (see u_strCompare for details).
- *
- * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
- *
- * @return A negative, zero, or positive integer indicating the comparison result.
- * @stable ICU 2.0
- */
- inline int8_t caseCompare(const UChar *srcChars,
- int32_t srcLength,
- uint32_t options) const;
- /**
- * Compare two strings case-insensitively using full case folding.
- * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param length The number of code units from this string to compare.
- * @param srcChars A pointer to another string to compare this one to.
- * @param options A bit set of options:
- * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
- * Comparison in code unit order with default case folding.
- *
- * - U_COMPARE_CODE_POINT_ORDER
- * Set to choose code point order instead of code unit order
- * (see u_strCompare for details).
- *
- * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
- *
- * @return A negative, zero, or positive integer indicating the comparison result.
- * @stable ICU 2.0
- */
- inline int8_t caseCompare(int32_t start,
- int32_t length,
- const UChar *srcChars,
- uint32_t options) const;
- /**
- * Compare two strings case-insensitively using full case folding.
- * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param length The number of code units from this string to compare.
- * @param srcChars A pointer to another string to compare this one to.
- * @param srcStart The start offset in that string at which the compare operation begins.
- * @param srcLength The number of code units from that string to compare.
- * @param options A bit set of options:
- * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
- * Comparison in code unit order with default case folding.
- *
- * - U_COMPARE_CODE_POINT_ORDER
- * Set to choose code point order instead of code unit order
- * (see u_strCompare for details).
- *
- * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
- *
- * @return A negative, zero, or positive integer indicating the comparison result.
- * @stable ICU 2.0
- */
- inline int8_t caseCompare(int32_t start,
- int32_t length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength,
- uint32_t options) const;
- /**
- * Compare two strings case-insensitively using full case folding.
- * This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)).
- *
- * @param start The start offset in this string at which the compare operation begins.
- * @param limit The offset after the last code unit from this string to compare.
- * @param srcText Another string to compare this one to.
- * @param srcStart The start offset in that string at which the compare operation begins.
- * @param srcLimit The offset after the last code unit from that string to compare.
- * @param options A bit set of options:
- * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
- * Comparison in code unit order with default case folding.
- *
- * - U_COMPARE_CODE_POINT_ORDER
- * Set to choose code point order instead of code unit order
- * (see u_strCompare for details).
- *
- * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
- *
- * @return A negative, zero, or positive integer indicating the comparison result.
- * @stable ICU 2.0
- */
- inline int8_t caseCompareBetween(int32_t start,
- int32_t limit,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLimit,
- uint32_t options) const;
- /**
- * Determine if this starts with the characters in <TT>text</TT>
- * @param text The text to match.
- * @return TRUE if this starts with the characters in <TT>text</TT>,
- * FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool startsWith(const UnicodeString& text) const;
- /**
- * Determine if this starts with the characters in <TT>srcText</TT>
- * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
- * @param srcText The text to match.
- * @param srcStart the offset into <TT>srcText</TT> to start matching
- * @param srcLength the number of characters in <TT>srcText</TT> to match
- * @return TRUE if this starts with the characters in <TT>text</TT>,
- * FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool startsWith(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const;
- /**
- * Determine if this starts with the characters in <TT>srcChars</TT>
- * @param srcChars The characters to match.
- * @param srcLength the number of characters in <TT>srcChars</TT>
- * @return TRUE if this starts with the characters in <TT>srcChars</TT>,
- * FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool startsWith(const UChar *srcChars,
- int32_t srcLength) const;
- /**
- * Determine if this ends with the characters in <TT>srcChars</TT>
- * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
- * @param srcChars The characters to match.
- * @param srcStart the offset into <TT>srcText</TT> to start matching
- * @param srcLength the number of characters in <TT>srcChars</TT> to match
- * @return TRUE if this ends with the characters in <TT>srcChars</TT>, FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool startsWith(const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const;
- /**
- * Determine if this ends with the characters in <TT>text</TT>
- * @param text The text to match.
- * @return TRUE if this ends with the characters in <TT>text</TT>,
- * FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool endsWith(const UnicodeString& text) const;
- /**
- * Determine if this ends with the characters in <TT>srcText</TT>
- * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
- * @param srcText The text to match.
- * @param srcStart the offset into <TT>srcText</TT> to start matching
- * @param srcLength the number of characters in <TT>srcText</TT> to match
- * @return TRUE if this ends with the characters in <TT>text</TT>,
- * FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool endsWith(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const;
- /**
- * Determine if this ends with the characters in <TT>srcChars</TT>
- * @param srcChars The characters to match.
- * @param srcLength the number of characters in <TT>srcChars</TT>
- * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
- * FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool endsWith(const UChar *srcChars,
- int32_t srcLength) const;
- /**
- * Determine if this ends with the characters in <TT>srcChars</TT>
- * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
- * @param srcChars The characters to match.
- * @param srcStart the offset into <TT>srcText</TT> to start matching
- * @param srcLength the number of characters in <TT>srcChars</TT> to match
- * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
- * FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool endsWith(const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const;
- /* Searching - bitwise only */
- /**
- * Locate in this the first occurrence of the characters in <TT>text</TT>,
- * using bitwise comparison.
- * @param text The text to search for.
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(const UnicodeString& text) const;
- /**
- * Locate in this the first occurrence of the characters in <TT>text</TT>
- * starting at offset <TT>start</TT>, using bitwise comparison.
- * @param text The text to search for.
- * @param start The offset at which searching will start.
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(const UnicodeString& text,
- int32_t start) const;
- /**
- * Locate in this the first occurrence in the range
- * [<TT>start</TT>, <TT>start + length</TT>) of the characters
- * in <TT>text</TT>, using bitwise comparison.
- * @param text The text to search for.
- * @param start The offset at which searching will start.
- * @param length The number of characters to search
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(const UnicodeString& text,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the first occurrence in the range
- * [<TT>start</TT>, <TT>start + length</TT>) of the characters
- * in <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
- * using bitwise comparison.
- * @param srcText The text to search for.
- * @param srcStart the offset into <TT>srcText</TT> at which
- * to start matching
- * @param srcLength the number of characters in <TT>srcText</TT> to match
- * @param start the offset into this at which to start matching
- * @param length the number of characters in this to search
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the first occurrence of the characters in
- * <TT>srcChars</TT>
- * starting at offset <TT>start</TT>, using bitwise comparison.
- * @param srcChars The text to search for.
- * @param srcLength the number of characters in <TT>srcChars</TT> to match
- * @param start the offset into this at which to start matching
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(const UChar *srcChars,
- int32_t srcLength,
- int32_t start) const;
- /**
- * Locate in this the first occurrence in the range
- * [<TT>start</TT>, <TT>start + length</TT>) of the characters
- * in <TT>srcChars</TT>, using bitwise comparison.
- * @param srcChars The text to search for.
- * @param srcLength the number of characters in <TT>srcChars</TT>
- * @param start The offset at which searching will start.
- * @param length The number of characters to search
- * @return The offset into this of the start of <TT>srcChars</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(const UChar *srcChars,
- int32_t srcLength,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the first occurrence in the range
- * [<TT>start</TT>, <TT>start + length</TT>) of the characters
- * in <TT>srcChars</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
- * using bitwise comparison.
- * @param srcChars The text to search for.
- * @param srcStart the offset into <TT>srcChars</TT> at which
- * to start matching
- * @param srcLength the number of characters in <TT>srcChars</TT> to match
- * @param start the offset into this at which to start matching
- * @param length the number of characters in this to search
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- int32_t indexOf(const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the first occurrence of the BMP code point <code>c</code>,
- * using bitwise comparison.
- * @param c The code unit to search for.
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(UChar c) const;
- /**
- * Locate in this the first occurrence of the code point <TT>c</TT>,
- * using bitwise comparison.
- *
- * @param c The code point to search for.
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(UChar32 c) const;
- /**
- * Locate in this the first occurrence of the BMP code point <code>c</code>,
- * starting at offset <TT>start</TT>, using bitwise comparison.
- * @param c The code unit to search for.
- * @param start The offset at which searching will start.
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(UChar c,
- int32_t start) const;
- /**
- * Locate in this the first occurrence of the code point <TT>c</TT>
- * starting at offset <TT>start</TT>, using bitwise comparison.
- *
- * @param c The code point to search for.
- * @param start The offset at which searching will start.
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(UChar32 c,
- int32_t start) const;
- /**
- * Locate in this the first occurrence of the BMP code point <code>c</code>
- * in the range [<TT>start</TT>, <TT>start + length</TT>),
- * using bitwise comparison.
- * @param c The code unit to search for.
- * @param start the offset into this at which to start matching
- * @param length the number of characters in this to search
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(UChar c,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the first occurrence of the code point <TT>c</TT>
- * in the range [<TT>start</TT>, <TT>start + length</TT>),
- * using bitwise comparison.
- *
- * @param c The code point to search for.
- * @param start the offset into this at which to start matching
- * @param length the number of characters in this to search
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t indexOf(UChar32 c,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the last occurrence of the characters in <TT>text</TT>,
- * using bitwise comparison.
- * @param text The text to search for.
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(const UnicodeString& text) const;
- /**
- * Locate in this the last occurrence of the characters in <TT>text</TT>
- * starting at offset <TT>start</TT>, using bitwise comparison.
- * @param text The text to search for.
- * @param start The offset at which searching will start.
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(const UnicodeString& text,
- int32_t start) const;
- /**
- * Locate in this the last occurrence in the range
- * [<TT>start</TT>, <TT>start + length</TT>) of the characters
- * in <TT>text</TT>, using bitwise comparison.
- * @param text The text to search for.
- * @param start The offset at which searching will start.
- * @param length The number of characters to search
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(const UnicodeString& text,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the last occurrence in the range
- * [<TT>start</TT>, <TT>start + length</TT>) of the characters
- * in <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
- * using bitwise comparison.
- * @param srcText The text to search for.
- * @param srcStart the offset into <TT>srcText</TT> at which
- * to start matching
- * @param srcLength the number of characters in <TT>srcText</TT> to match
- * @param start the offset into this at which to start matching
- * @param length the number of characters in this to search
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the last occurrence of the characters in <TT>srcChars</TT>
- * starting at offset <TT>start</TT>, using bitwise comparison.
- * @param srcChars The text to search for.
- * @param srcLength the number of characters in <TT>srcChars</TT> to match
- * @param start the offset into this at which to start matching
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(const UChar *srcChars,
- int32_t srcLength,
- int32_t start) const;
- /**
- * Locate in this the last occurrence in the range
- * [<TT>start</TT>, <TT>start + length</TT>) of the characters
- * in <TT>srcChars</TT>, using bitwise comparison.
- * @param srcChars The text to search for.
- * @param srcLength the number of characters in <TT>srcChars</TT>
- * @param start The offset at which searching will start.
- * @param length The number of characters to search
- * @return The offset into this of the start of <TT>srcChars</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(const UChar *srcChars,
- int32_t srcLength,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the last occurrence in the range
- * [<TT>start</TT>, <TT>start + length</TT>) of the characters
- * in <TT>srcChars</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
- * using bitwise comparison.
- * @param srcChars The text to search for.
- * @param srcStart the offset into <TT>srcChars</TT> at which
- * to start matching
- * @param srcLength the number of characters in <TT>srcChars</TT> to match
- * @param start the offset into this at which to start matching
- * @param length the number of characters in this to search
- * @return The offset into this of the start of <TT>text</TT>,
- * or -1 if not found.
- * @stable ICU 2.0
- */
- int32_t lastIndexOf(const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the last occurrence of the BMP code point <code>c</code>,
- * using bitwise comparison.
- * @param c The code unit to search for.
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(UChar c) const;
- /**
- * Locate in this the last occurrence of the code point <TT>c</TT>,
- * using bitwise comparison.
- *
- * @param c The code point to search for.
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(UChar32 c) const;
- /**
- * Locate in this the last occurrence of the BMP code point <code>c</code>
- * starting at offset <TT>start</TT>, using bitwise comparison.
- * @param c The code unit to search for.
- * @param start The offset at which searching will start.
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(UChar c,
- int32_t start) const;
- /**
- * Locate in this the last occurrence of the code point <TT>c</TT>
- * starting at offset <TT>start</TT>, using bitwise comparison.
- *
- * @param c The code point to search for.
- * @param start The offset at which searching will start.
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(UChar32 c,
- int32_t start) const;
- /**
- * Locate in this the last occurrence of the BMP code point <code>c</code>
- * in the range [<TT>start</TT>, <TT>start + length</TT>),
- * using bitwise comparison.
- * @param c The code unit to search for.
- * @param start the offset into this at which to start matching
- * @param length the number of characters in this to search
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(UChar c,
- int32_t start,
- int32_t length) const;
- /**
- * Locate in this the last occurrence of the code point <TT>c</TT>
- * in the range [<TT>start</TT>, <TT>start + length</TT>),
- * using bitwise comparison.
- *
- * @param c The code point to search for.
- * @param start the offset into this at which to start matching
- * @param length the number of characters in this to search
- * @return The offset into this of <TT>c</TT>, or -1 if not found.
- * @stable ICU 2.0
- */
- inline int32_t lastIndexOf(UChar32 c,
- int32_t start,
- int32_t length) const;
- /* Character access */
- /**
- * Return the code unit at offset <tt>offset</tt>.
- * If the offset is not valid (0..length()-1) then U+ffff is returned.
- * @param offset a valid offset into the text
- * @return the code unit at offset <tt>offset</tt>
- * or 0xffff if the offset is not valid for this string
- * @stable ICU 2.0
- */
- inline UChar charAt(int32_t offset) const;
- /**
- * Return the code unit at offset <tt>offset</tt>.
- * If the offset is not valid (0..length()-1) then U+ffff is returned.
- * @param offset a valid offset into the text
- * @return the code unit at offset <tt>offset</tt>
- * @stable ICU 2.0
- */
- inline UChar operator[] (int32_t offset) const;
- /**
- * Return the code point that contains the code unit
- * at offset <tt>offset</tt>.
- * If the offset is not valid (0..length()-1) then U+ffff is returned.
- * @param offset a valid offset into the text
- * that indicates the text offset of any of the code units
- * that will be assembled into a code point (21-bit value) and returned
- * @return the code point of text at <tt>offset</tt>
- * or 0xffff if the offset is not valid for this string
- * @stable ICU 2.0
- */
- inline UChar32 char32At(int32_t offset) const;
- /**
- * Adjust a random-access offset so that
- * it points to the beginning of a Unicode character.
- * The offset that is passed in points to
- * any code unit of a code point,
- * while the returned offset will point to the first code unit
- * of the same code point.
- * In UTF-16, if the input offset points to a second surrogate
- * of a surrogate pair, then the returned offset will point
- * to the first surrogate.
- * @param offset a valid offset into one code point of the text
- * @return offset of the first code unit of the same code point
- * @see U16_SET_CP_START
- * @stable ICU 2.0
- */
- inline int32_t getChar32Start(int32_t offset) const;
- /**
- * Adjust a random-access offset so that
- * it points behind a Unicode character.
- * The offset that is passed in points behind
- * any code unit of a code point,
- * while the returned offset will point behind the last code unit
- * of the same code point.
- * In UTF-16, if the input offset points behind the first surrogate
- * (i.e., to the second surrogate)
- * of a surrogate pair, then the returned offset will point
- * behind the second surrogate (i.e., to the first surrogate).
- * @param offset a valid offset after any code unit of a code point of the text
- * @return offset of the first code unit after the same code point
- * @see U16_SET_CP_LIMIT
- * @stable ICU 2.0
- */
- inline int32_t getChar32Limit(int32_t offset) const;
- /**
- * Move the code unit index along the string by delta code points.
- * Interpret the input index as a code unit-based offset into the string,
- * move the index forward or backward by delta code points, and
- * return the resulting index.
- * The input index should point to the first code unit of a code point,
- * if there is more than one.
- *
- * Both input and output indexes are code unit-based as for all
- * string indexes/offsets in ICU (and other libraries, like MBCS char*).
- * If delta<0 then the index is moved backward (toward the start of the string).
- * If delta>0 then the index is moved forward (toward the end of the string).
- *
- * This behaves like CharacterIterator::move32(delta, kCurrent).
- *
- * Behavior for out-of-bounds indexes:
- * <code>moveIndex32</code> pins the input index to 0..length(), i.e.,
- * if the input index<0 then it is pinned to 0;
- * if it is index>length() then it is pinned to length().
- * Afterwards, the index is moved by <code>delta</code> code points
- * forward or backward,
- * but no further backward than to 0 and no further forward than to length().
- * The resulting index return value will be in between 0 and length(), inclusively.
- *
- * Examples:
- * <pre>
- * // s has code points 'a' U+10000 'b' U+10ffff U+2029
- * UnicodeString s=UNICODE_STRING("a\\U00010000b\\U0010ffff\\u2029", 31).unescape();
- *
- * // initial index: position of U+10000
- * int32_t index=1;
- *
- * // the following examples will all result in index==4, position of U+10ffff
- *
- * // skip 2 code points from some position in the string
- * index=s.moveIndex32(index, 2); // skips U+10000 and 'b'
- *
- * // go to the 3rd code point from the start of s (0-based)
- * index=s.moveIndex32(0, 3); // skips 'a', U+10000, and 'b'
- *
- * // go to the next-to-last code point of s
- * index=s.moveIndex32(s.length(), -2); // backward-skips U+2029 and U+10ffff
- * </pre>
- *
- * @param index input code unit index
- * @param delta (signed) code point count to move the index forward or backward
- * in the string
- * @return the resulting code unit index
- * @stable ICU 2.0
- */
- int32_t moveIndex32(int32_t index, int32_t delta) const;
- /* Substring extraction */
- /**
- * Copy the characters in the range
- * [<tt>start</tt>, <tt>start + length</tt>) into the array <tt>dst</tt>,
- * beginning at <tt>dstStart</tt>.
- * If the string aliases to <code>dst</code> itself as an external buffer,
- * then extract() will not copy the contents.
- *
- * @param start offset of first character which will be copied into the array
- * @param length the number of characters to extract
- * @param dst array in which to copy characters. The length of <tt>dst</tt>
- * must be at least (<tt>dstStart + length</tt>).
- * @param dstStart the offset in <TT>dst</TT> where the first character
- * will be extracted
- * @stable ICU 2.0
- */
- inline void extract(int32_t start,
- int32_t length,
- UChar *dst,
- int32_t dstStart = 0) const;
- /**
- * Copy the contents of the string into dest.
- * This is a convenience function that
- * checks if there is enough space in dest,
- * extracts the entire string if possible,
- * and NUL-terminates dest if possible.
- *
- * If the string fits into dest but cannot be NUL-terminated
- * (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING.
- * If the string itself does not fit into dest
- * (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR.
- *
- * If the string aliases to <code>dest</code> itself as an external buffer,
- * then extract() will not copy the contents.
- *
- * @param dest Destination string buffer.
- * @param destCapacity Number of UChars available at dest.
- * @param errorCode ICU error code.
- * @return length()
- * @stable ICU 2.0
- */
- int32_t
- extract(UChar *dest, int32_t destCapacity,
- UErrorCode &errorCode) const;
- /**
- * Copy the characters in the range
- * [<tt>start</tt>, <tt>start + length</tt>) into the UnicodeString
- * <tt>target</tt>.
- * @param start offset of first character which will be copied
- * @param length the number of characters to extract
- * @param target UnicodeString into which to copy characters.
- * @return A reference to <TT>target</TT>
- * @stable ICU 2.0
- */
- inline void extract(int32_t start,
- int32_t length,
- UnicodeString& target) const;
- /**
- * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
- * into the array <tt>dst</tt>, beginning at <tt>dstStart</tt>.
- * @param start offset of first character which will be copied into the array
- * @param limit offset immediately following the last character to be copied
- * @param dst array in which to copy characters. The length of <tt>dst</tt>
- * must be at least (<tt>dstStart + (limit - start)</tt>).
- * @param dstStart the offset in <TT>dst</TT> where the first character
- * will be extracted
- * @stable ICU 2.0
- */
- inline void extractBetween(int32_t start,
- int32_t limit,
- UChar *dst,
- int32_t dstStart = 0) const;
- /**
- * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
- * into the UnicodeString <tt>target</tt>. Replaceable API.
- * @param start offset of first character which will be copied
- * @param limit offset immediately following the last character to be copied
- * @param target UnicodeString into which to copy characters.
- * @return A reference to <TT>target</TT>
- * @stable ICU 2.0
- */
- virtual void extractBetween(int32_t start,
- int32_t limit,
- UnicodeString& target) const;
- /**
- * Copy the characters in the range
- * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters.
- * All characters must be invariant (see utypes.h).
- * Use US_INV as the last, signature-distinguishing parameter.
- *
- * This function does not write any more than <code>targetLength</code>
- * characters but returns the length of the entire output string
- * so that one can allocate a larger buffer and call the function again
- * if necessary.
- * The output string is NUL-terminated if possible.
- *
- * @param start offset of first character which will be copied
- * @param startLength the number of characters to extract
- * @param target the target buffer for extraction, can be NULL
- * if targetLength is 0
- * @param targetCapacity the length of the target buffer
- * @param inv Signature-distinguishing paramater, use US_INV.
- * @return the output string length, not including the terminating NUL
- * @stable ICU 3.2
- */
- int32_t extract(int32_t start,
- int32_t startLength,
- char *target,
- int32_t targetCapacity,
- enum EInvariant inv) const;
- #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
- /**
- * Copy the characters in the range
- * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
- * in the platform's default codepage.
- * This function does not write any more than <code>targetLength</code>
- * characters but returns the length of the entire output string
- * so that one can allocate a larger buffer and call the function again
- * if necessary.
- * The output string is NUL-terminated if possible.
- *
- * @param start offset of first character which will be copied
- * @param startLength the number of characters to extract
- * @param target the target buffer for extraction
- * @param targetLength the length of the target buffer
- * If <TT>target</TT> is NULL, then the number of bytes required for
- * <TT>target</TT> is returned.
- * @return the output string length, not including the terminating NUL
- * @stable ICU 2.0
- */
- int32_t extract(int32_t start,
- int32_t startLength,
- char *target,
- uint32_t targetLength) const;
- #endif
- #if !UCONFIG_NO_CONVERSION
- /**
- * Copy the characters in the range
- * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
- * in a specified codepage.
- * The output string is NUL-terminated.
- *
- * Recommendation: For invariant-character strings use
- * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
- * because it avoids object code dependencies of UnicodeString on
- * the conversion code.
- *
- * @param start offset of first character which will be copied
- * @param startLength the number of characters to extract
- * @param target the target buffer for extraction
- * @param codepage the desired codepage for the characters. 0 has
- * the special meaning of the default codepage
- * If <code>codepage</code> is an empty string (<code>""</code>),
- * then a simple conversion is performed on the codepage-invariant
- * subset ("invariant characters") of the platform encoding. See utypes.h.
- * If <TT>target</TT> is NULL, then the number of bytes required for
- * <TT>target</TT> is returned. It is assumed that the target is big enough
- * to fit all of the characters.
- * @return the output string length, not including the terminating NUL
- * @stable ICU 2.0
- */
- inline int32_t extract(int32_t start,
- int32_t startLength,
- char *target,
- const char *codepage = 0) const;
- /**
- * Copy the characters in the range
- * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
- * in a specified codepage.
- * This function does not write any more than <code>targetLength</code>
- * characters but returns the length of the entire output string
- * so that one can allocate a larger buffer and call the function again
- * if necessary.
- * The output string is NUL-terminated if possible.
- *
- * Recommendation: For invariant-character strings use
- * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
- * because it avoids object code dependencies of UnicodeString on
- * the conversion code.
- *
- * @param start offset of first character which will be copied
- * @param startLength the number of characters to extract
- * @param target the target buffer for extraction
- * @param targetLength the length of the target buffer
- * @param codepage the desired codepage for the characters. 0 has
- * the special meaning of the default codepage
- * If <code>codepage</code> is an empty string (<code>""</code>),
- * then a simple conversion is performed on the codepage-invariant
- * subset ("invariant characters") of the platform encoding. See utypes.h.
- * If <TT>target</TT> is NULL, then the number of bytes required for
- * <TT>target</TT> is returned.
- * @return the output string length, not including the terminating NUL
- * @stable ICU 2.0
- */
- int32_t extract(int32_t start,
- int32_t startLength,
- char *target,
- uint32_t targetLength,
- const char *codepage) const;
- /**
- * Convert the UnicodeString into a codepage string using an existing UConverter.
- * The output string is NUL-terminated if possible.
- *
- * This function avoids the overhead of opening and closing a converter if
- * multiple strings are extracted.
- *
- * @param dest destination string buffer, can be NULL if destCapacity==0
- * @param destCapacity the number of chars available at dest
- * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called),
- * or NULL for the default converter
- * @param errorCode normal ICU error code
- * @return the length of the output string, not counting the terminating NUL;
- * if the length is greater than destCapacity, then the string will not fit
- * and a buffer of the indicated length would need to be passed in
- * @stable ICU 2.0
- */
- int32_t extract(char *dest, int32_t destCapacity,
- UConverter *cnv,
- UErrorCode &errorCode) const;
- #endif
- /**
- * Create a temporary substring for the specified range.
- * Unlike the substring constructor and setTo() functions,
- * the object returned here will be a read-only alias (using getBuffer())
- * rather than copying the text.
- * As a result, this substring operation is much faster but requires
- * that the original string not be modified or deleted during the lifetime
- * of the returned substring object.
- * @param start offset of the first character visible in the substring
- * @param length length of the substring
- * @return a read-only alias UnicodeString object for the substring
- * @stable ICU 4.4
- */
- UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
- /**
- * Create a temporary substring for the specified range.
- * Same as tempSubString(start, length) except that the substring range
- * is specified as a (start, limit) pair (with an exclusive limit index)
- * rather than a (start, length) pair.
- * @param start offset of the first character visible in the substring
- * @param limit offset immediately following the last character visible in the substring
- * @return a read-only alias UnicodeString object for the substring
- * @stable ICU 4.4
- */
- inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
- /**
- * Convert the UnicodeString to UTF-8 and write the result
- * to a ByteSink. This is called by toUTF8String().
- * Unpaired surrogates are replaced with U+FFFD.
- * Calls u_strToUTF8WithSub().
- *
- * @param sink A ByteSink to which the UTF-8 version of the string is written.
- * sink.Flush() is called at the end.
- * @stable ICU 4.2
- * @see toUTF8String
- */
- void toUTF8(ByteSink &sink) const;
- #if U_HAVE_STD_STRING
- /**
- * Convert the UnicodeString to UTF-8 and append the result
- * to a standard string.
- * Unpaired surrogates are replaced with U+FFFD.
- * Calls toUTF8().
- *
- * @param result A standard string (or a compatible object)
- * to which the UTF-8 version of the string is appended.
- * @return The string object.
- * @stable ICU 4.2
- * @see toUTF8
- */
- template<typename StringClass>
- StringClass &toUTF8String(StringClass &result) const {
- StringByteSink<StringClass> sbs(&result);
- toUTF8(sbs);
- return result;
- }
- #endif
- /**
- * Convert the UnicodeString to UTF-32.
- * Unpaired surrogates are replaced with U+FFFD.
- * Calls u_strToUTF32WithSub().
- *
- * @param utf32 destination string buffer, can be NULL if capacity==0
- * @param capacity the number of UChar32s available at utf32
- * @param errorCode Standard ICU error code. Its input value must
- * pass the U_SUCCESS() test, or else the function returns
- * immediately. Check for U_FAILURE() on output or use with
- * function chaining. (See User Guide for details.)
- * @return The length of the UTF-32 string.
- * @see fromUTF32
- * @stable ICU 4.2
- */
- int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
- /* Length operations */
- /**
- * Return the length of the UnicodeString object.
- * The length is the number of UChar code units are in the UnicodeString.
- * If you want the number of code points, please use countChar32().
- * @return the length of the UnicodeString object
- * @see countChar32
- * @stable ICU 2.0
- */
- inline int32_t length(void) const;
- /**
- * Count Unicode code points in the length UChar code units of the string.
- * A code point may occupy either one or two UChar code units.
- * Counting code points involves reading all code units.
- *
- * This functions is basically the inverse of moveIndex32().
- *
- * @param start the index of the first code unit to check
- * @param length the number of UChar code units to check
- * @return the number of code points in the specified code units
- * @see length
- * @stable ICU 2.0
- */
- int32_t
- countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
- /**
- * Check if the length UChar code units of the string
- * contain more Unicode code points than a certain number.
- * This is more efficient than counting all code points in this part of the string
- * and comparing that number with a threshold.
- * This function may not need to scan the string at all if the length
- * falls within a certain range, and
- * never needs to count more than 'number+1' code points.
- * Logically equivalent to (countChar32(start, length)>number).
- * A Unicode code point may occupy either one or two UChar code units.
- *
- * @param start the index of the first code unit to check (0 for the entire string)
- * @param length the number of UChar code units to check
- * (use INT32_MAX for the entire string; remember that start/length
- * values are pinned)
- * @param number The number of code points in the (sub)string is compared against
- * the 'number' parameter.
- * @return Boolean value for whether the string contains more Unicode code points
- * than 'number'. Same as (u_countChar32(s, length)>number).
- * @see countChar32
- * @see u_strHasMoreChar32Than
- * @stable ICU 2.4
- */
- UBool
- hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
- /**
- * Determine if this string is empty.
- * @return TRUE if this string contains 0 characters, FALSE otherwise.
- * @stable ICU 2.0
- */
- inline UBool isEmpty(void) const;
- /**
- * Return the capacity of the internal buffer of the UnicodeString object.
- * This is useful together with the getBuffer functions.
- * See there for details.
- *
- * @return the number of UChars available in the internal buffer
- * @see getBuffer
- * @stable ICU 2.0
- */
- inline int32_t getCapacity(void) const;
- /* Other operations */
- /**
- * Generate a hash code for this object.
- * @return The hash code of this UnicodeString.
- * @stable ICU 2.0
- */
- inline int32_t hashCode(void) const;
- /**
- * Determine if this object contains a valid string.
- * A bogus string has no value. It is different from an empty string,
- * although in both cases isEmpty() returns TRUE and length() returns 0.
- * setToBogus() and isBogus() can be used to indicate that no string value is available.
- * For a bogus string, getBuffer() and getTerminatedBuffer() return NULL, and
- * length() returns 0.
- *
- * @return TRUE if the string is valid, FALSE otherwise
- * @see setToBogus()
- * @stable ICU 2.0
- */
- inline UBool isBogus(void) const;
- //========================================
- // Write operations
- //========================================
- /* Assignment operations */
- /**
- * Assignment operator. Replace the characters in this UnicodeString
- * with the characters from <TT>srcText</TT>.
- * @param srcText The text containing the characters to replace
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString &operator=(const UnicodeString &srcText);
- /**
- * Almost the same as the assignment operator.
- * Replace the characters in this UnicodeString
- * with the characters from <code>srcText</code>.
- *
- * This function works the same for all strings except for ones that
- * are readonly aliases.
- * Starting with ICU 2.4, the assignment operator and the copy constructor
- * allocate a new buffer and copy the buffer contents even for readonly aliases.
- * This function implements the old, more efficient but less safe behavior
- * of making this string also a readonly alias to the same buffer.
- * The fastCopyFrom function must be used only if it is known that the lifetime of
- * this UnicodeString is at least as long as the lifetime of the aliased buffer
- * including its contents, for example for strings from resource bundles
- * or aliases to string contents.
- *
- * @param src The text containing the characters to replace.
- * @return a reference to this
- * @stable ICU 2.4
- */
- UnicodeString &fastCopyFrom(const UnicodeString &src);
- /**
- * Assignment operator. Replace the characters in this UnicodeString
- * with the code unit <TT>ch</TT>.
- * @param ch the code unit to replace
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& operator= (UChar ch);
- /**
- * Assignment operator. Replace the characters in this UnicodeString
- * with the code point <TT>ch</TT>.
- * @param ch the code point to replace
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& operator= (UChar32 ch);
- /**
- * Set the text in the UnicodeString object to the characters
- * in <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcText.length()</TT>).
- * <TT>srcText</TT> is not modified.
- * @param srcText the source for the new characters
- * @param srcStart the offset into <TT>srcText</TT> where new characters
- * will be obtained
- * @return a reference to this
- * @stable ICU 2.2
- */
- inline UnicodeString& setTo(const UnicodeString& srcText,
- int32_t srcStart);
- /**
- * Set the text in the UnicodeString object to the characters
- * in <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
- * <TT>srcText</TT> is not modified.
- * @param srcText the source for the new characters
- * @param srcStart the offset into <TT>srcText</TT> where new characters
- * will be obtained
- * @param srcLength the number of characters in <TT>srcText</TT> in the
- * replace string.
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& setTo(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength);
- /**
- * Set the text in the UnicodeString object to the characters in
- * <TT>srcText</TT>.
- * <TT>srcText</TT> is not modified.
- * @param srcText the source for the new characters
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& setTo(const UnicodeString& srcText);
- /**
- * Set the characters in the UnicodeString object to the characters
- * in <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
- * @param srcChars the source for the new characters
- * @param srcLength the number of Unicode characters in srcChars.
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& setTo(const UChar *srcChars,
- int32_t srcLength);
- /**
- * Set the characters in the UnicodeString object to the code unit
- * <TT>srcChar</TT>.
- * @param srcChar the code unit which becomes the UnicodeString's character
- * content
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString& setTo(UChar srcChar);
- /**
- * Set the characters in the UnicodeString object to the code point
- * <TT>srcChar</TT>.
- * @param srcChar the code point which becomes the UnicodeString's character
- * content
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString& setTo(UChar32 srcChar);
- /**
- * Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor.
- * The text will be used for the UnicodeString object, but
- * it will not be released when the UnicodeString is destroyed.
- * This has copy-on-write semantics:
- * When the string is modified, then the buffer is first copied into
- * newly allocated memory.
- * The aliased buffer is never modified.
- * In an assignment to another UnicodeString, the text will be aliased again,
- * so that both strings then alias the same readonly-text.
- *
- * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
- * This must be true if <code>textLength==-1</code>.
- * @param text The characters to alias for the UnicodeString.
- * @param textLength The number of Unicode characters in <code>text</code> to alias.
- * If -1, then this constructor will determine the length
- * by calling <code>u_strlen()</code>.
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString &setTo(UBool isTerminated,
- const UChar *text,
- int32_t textLength);
- /**
- * Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor.
- * The text will be used for the UnicodeString object, but
- * it will not be released when the UnicodeString is destroyed.
- * This has write-through semantics:
- * For as long as the capacity of the buffer is sufficient, write operations
- * will directly affect the buffer. When more capacity is necessary, then
- * a new buffer will be allocated and the contents copied as with regularly
- * constructed strings.
- * In an assignment to another UnicodeString, the buffer will be copied.
- * The extract(UChar *dst) function detects whether the dst pointer is the same
- * as the string buffer itself and will in this case not copy the contents.
- *
- * @param buffer The characters to alias for the UnicodeString.
- * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
- * @param buffCapacity The size of <code>buffer</code> in UChars.
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString &setTo(UChar *buffer,
- int32_t buffLength,
- int32_t buffCapacity);
- /**
- * Make this UnicodeString object invalid.
- * The string will test TRUE with isBogus().
- *
- * A bogus string has no value. It is different from an empty string.
- * It can be used to indicate that no string value is available.
- * getBuffer() and getTerminatedBuffer() return NULL, and
- * length() returns 0.
- *
- * This utility function is used throughout the UnicodeString
- * implementation to indicate that a UnicodeString operation failed,
- * and may be used in other functions,
- * especially but not exclusively when such functions do not
- * take a UErrorCode for simplicity.
- *
- * The following methods, and no others, will clear a string object's bogus flag:
- * - remove()
- * - remove(0, INT32_MAX)
- * - truncate(0)
- * - operator=() (assignment operator)
- * - setTo(...)
- *
- * The simplest ways to turn a bogus string into an empty one
- * is to use the remove() function.
- * Examples for other functions that are equivalent to "set to empty string":
- * \code
- * if(s.isBogus()) {
- * s.remove(); // set to an empty string (remove all), or
- * s.remove(0, INT32_MAX); // set to an empty string (remove all), or
- * s.truncate(0); // set to an empty string (complete truncation), or
- * s=UnicodeString(); // assign an empty string, or
- * s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or
- * static const UChar nul=0;
- * s.setTo(&nul, 0); // set to an empty C Unicode string
- * }
- * \endcode
- *
- * @see isBogus()
- * @stable ICU 2.0
- */
- void setToBogus();
- /**
- * Set the character at the specified offset to the specified character.
- * @param offset A valid offset into the text of the character to set
- * @param ch The new character
- * @return A reference to this
- * @stable ICU 2.0
- */
- UnicodeString& setCharAt(int32_t offset,
- UChar ch);
- /* Append operations */
- /**
- * Append operator. Append the code unit <TT>ch</TT> to the UnicodeString
- * object.
- * @param ch the code unit to be appended
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& operator+= (UChar ch);
- /**
- * Append operator. Append the code point <TT>ch</TT> to the UnicodeString
- * object.
- * @param ch the code point to be appended
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& operator+= (UChar32 ch);
- /**
- * Append operator. Append the characters in <TT>srcText</TT> to the
- * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT> is
- * not modified.
- * @param srcText the source for the new characters
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& operator+= (const UnicodeString& srcText);
- /**
- * Append the characters
- * in <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the
- * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT>
- * is not modified.
- * @param srcText the source for the new characters
- * @param srcStart the offset into <TT>srcText</TT> where new characters
- * will be obtained
- * @param srcLength the number of characters in <TT>srcText</TT> in
- * the append string
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& append(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength);
- /**
- * Append the characters in <TT>srcText</TT> to the UnicodeString object at
- * offset <TT>start</TT>. <TT>srcText</TT> is not modified.
- * @param srcText the source for the new characters
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& append(const UnicodeString& srcText);
- /**
- * Append the characters in <TT>srcChars</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the UnicodeString
- * object at offset
- * <TT>start</TT>. <TT>srcChars</TT> is not modified.
- * @param srcChars the source for the new characters
- * @param srcStart the offset into <TT>srcChars</TT> where new characters
- * will be obtained
- * @param srcLength the number of characters in <TT>srcChars</TT> in
- * the append string
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& append(const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength);
- /**
- * Append the characters in <TT>srcChars</TT> to the UnicodeString object
- * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
- * @param srcChars the source for the new characters
- * @param srcLength the number of Unicode characters in <TT>srcChars</TT>
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& append(const UChar *srcChars,
- int32_t srcLength);
- /**
- * Append the code unit <TT>srcChar</TT> to the UnicodeString object.
- * @param srcChar the code unit to append
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& append(UChar srcChar);
- /**
- * Append the code point <TT>srcChar</TT> to the UnicodeString object.
- * @param srcChar the code point to append
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& append(UChar32 srcChar);
- /* Insert operations */
- /**
- * Insert the characters in <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
- * object at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
- * @param start the offset where the insertion begins
- * @param srcText the source for the new characters
- * @param srcStart the offset into <TT>srcText</TT> where new characters
- * will be obtained
- * @param srcLength the number of characters in <TT>srcText</TT> in
- * the insert string
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& insert(int32_t start,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength);
- /**
- * Insert the characters in <TT>srcText</TT> into the UnicodeString object
- * at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
- * @param start the offset where the insertion begins
- * @param srcText the source for the new characters
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& insert(int32_t start,
- const UnicodeString& srcText);
- /**
- * Insert the characters in <TT>srcChars</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
- * object at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
- * @param start the offset at which the insertion begins
- * @param srcChars the source for the new characters
- * @param srcStart the offset into <TT>srcChars</TT> where new characters
- * will be obtained
- * @param srcLength the number of characters in <TT>srcChars</TT>
- * in the insert string
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& insert(int32_t start,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength);
- /**
- * Insert the characters in <TT>srcChars</TT> into the UnicodeString object
- * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
- * @param start the offset where the insertion begins
- * @param srcChars the source for the new characters
- * @param srcLength the number of Unicode characters in srcChars.
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& insert(int32_t start,
- const UChar *srcChars,
- int32_t srcLength);
- /**
- * Insert the code unit <TT>srcChar</TT> into the UnicodeString object at
- * offset <TT>start</TT>.
- * @param start the offset at which the insertion occurs
- * @param srcChar the code unit to insert
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& insert(int32_t start,
- UChar srcChar);
- /**
- * Insert the code point <TT>srcChar</TT> into the UnicodeString object at
- * offset <TT>start</TT>.
- * @param start the offset at which the insertion occurs
- * @param srcChar the code point to insert
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& insert(int32_t start,
- UChar32 srcChar);
- /* Replace operations */
- /**
- * Replace the characters in the range
- * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
- * <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
- * <TT>srcText</TT> is not modified.
- * @param start the offset at which the replace operation begins
- * @param length the number of characters to replace. The character at
- * <TT>start + length</TT> is not modified.
- * @param srcText the source for the new characters
- * @param srcStart the offset into <TT>srcText</TT> where new characters
- * will be obtained
- * @param srcLength the number of characters in <TT>srcText</TT> in
- * the replace string
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString& replace(int32_t start,
- int32_t length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength);
- /**
- * Replace the characters in the range
- * [<TT>start</TT>, <TT>start + length</TT>)
- * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is
- * not modified.
- * @param start the offset at which the replace operation begins
- * @param length the number of characters to replace. The character at
- * <TT>start + length</TT> is not modified.
- * @param srcText the source for the new characters
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString& replace(int32_t start,
- int32_t length,
- const UnicodeString& srcText);
- /**
- * Replace the characters in the range
- * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
- * <TT>srcChars</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). <TT>srcChars</TT>
- * is not modified.
- * @param start the offset at which the replace operation begins
- * @param length the number of characters to replace. The character at
- * <TT>start + length</TT> is not modified.
- * @param srcChars the source for the new characters
- * @param srcStart the offset into <TT>srcChars</TT> where new characters
- * will be obtained
- * @param srcLength the number of characters in <TT>srcChars</TT>
- * in the replace string
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString& replace(int32_t start,
- int32_t length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength);
- /**
- * Replace the characters in the range
- * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
- * <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
- * @param start the offset at which the replace operation begins
- * @param length number of characters to replace. The character at
- * <TT>start + length</TT> is not modified.
- * @param srcChars the source for the new characters
- * @param srcLength the number of Unicode characters in srcChars
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& replace(int32_t start,
- int32_t length,
- const UChar *srcChars,
- int32_t srcLength);
- /**
- * Replace the characters in the range
- * [<TT>start</TT>, <TT>start + length</TT>) with the code unit
- * <TT>srcChar</TT>.
- * @param start the offset at which the replace operation begins
- * @param length the number of characters to replace. The character at
- * <TT>start + length</TT> is not modified.
- * @param srcChar the new code unit
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& replace(int32_t start,
- int32_t length,
- UChar srcChar);
- /**
- * Replace the characters in the range
- * [<TT>start</TT>, <TT>start + length</TT>) with the code point
- * <TT>srcChar</TT>.
- * @param start the offset at which the replace operation begins
- * @param length the number of characters to replace. The character at
- * <TT>start + length</TT> is not modified.
- * @param srcChar the new code point
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& replace(int32_t start,
- int32_t length,
- UChar32 srcChar);
- /**
- * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
- * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is not modified.
- * @param start the offset at which the replace operation begins
- * @param limit the offset immediately following the replace range
- * @param srcText the source for the new characters
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& replaceBetween(int32_t start,
- int32_t limit,
- const UnicodeString& srcText);
- /**
- * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
- * with the characters in <TT>srcText</TT> in the range
- * [<TT>srcStart</TT>, <TT>srcLimit</TT>). <TT>srcText</TT> is not modified.
- * @param start the offset at which the replace operation begins
- * @param limit the offset immediately following the replace range
- * @param srcText the source for the new characters
- * @param srcStart the offset into <TT>srcChars</TT> where new characters
- * will be obtained
- * @param srcLimit the offset immediately following the range to copy
- * in <TT>srcText</TT>
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& replaceBetween(int32_t start,
- int32_t limit,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLimit);
- /**
- * Replace a substring of this object with the given text.
- * @param start the beginning index, inclusive; <code>0 <= start
- * <= limit</code>.
- * @param limit the ending index, exclusive; <code>start <= limit
- * <= length()</code>.
- * @param text the text to replace characters <code>start</code>
- * to <code>limit - 1</code>
- * @stable ICU 2.0
- */
- virtual void handleReplaceBetween(int32_t start,
- int32_t limit,
- const UnicodeString& text);
- /**
- * Replaceable API
- * @return TRUE if it has MetaData
- * @stable ICU 2.4
- */
- virtual UBool hasMetaData() const;
- /**
- * Copy a substring of this object, retaining attribute (out-of-band)
- * information. This method is used to duplicate or reorder substrings.
- * The destination index must not overlap the source range.
- *
- * @param start the beginning index, inclusive; <code>0 <= start <=
- * limit</code>.
- * @param limit the ending index, exclusive; <code>start <= limit <=
- * length()</code>.
- * @param dest the destination index. The characters from
- * <code>start..limit-1</code> will be copied to <code>dest</code>.
- * Implementations of this method may assume that <code>dest <= start ||
- * dest >= limit</code>.
- * @stable ICU 2.0
- */
- virtual void copy(int32_t start, int32_t limit, int32_t dest);
- /* Search and replace operations */
- /**
- * Replace all occurrences of characters in oldText with the characters
- * in newText
- * @param oldText the text containing the search text
- * @param newText the text containing the replacement text
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& findAndReplace(const UnicodeString& oldText,
- const UnicodeString& newText);
- /**
- * Replace all occurrences of characters in oldText with characters
- * in newText
- * in the range [<TT>start</TT>, <TT>start + length</TT>).
- * @param start the start of the range in which replace will performed
- * @param length the length of the range in which replace will be performed
- * @param oldText the text containing the search text
- * @param newText the text containing the replacement text
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& findAndReplace(int32_t start,
- int32_t length,
- const UnicodeString& oldText,
- const UnicodeString& newText);
- /**
- * Replace all occurrences of characters in oldText in the range
- * [<TT>oldStart</TT>, <TT>oldStart + oldLength</TT>) with the characters
- * in newText in the range
- * [<TT>newStart</TT>, <TT>newStart + newLength</TT>)
- * in the range [<TT>start</TT>, <TT>start + length</TT>).
- * @param start the start of the range in which replace will performed
- * @param length the length of the range in which replace will be performed
- * @param oldText the text containing the search text
- * @param oldStart the start of the search range in <TT>oldText</TT>
- * @param oldLength the length of the search range in <TT>oldText</TT>
- * @param newText the text containing the replacement text
- * @param newStart the start of the replacement range in <TT>newText</TT>
- * @param newLength the length of the replacement range in <TT>newText</TT>
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString& findAndReplace(int32_t start,
- int32_t length,
- const UnicodeString& oldText,
- int32_t oldStart,
- int32_t oldLength,
- const UnicodeString& newText,
- int32_t newStart,
- int32_t newLength);
- /* Remove operations */
- /**
- * Remove all characters from the UnicodeString object.
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& remove(void);
- /**
- * Remove the characters in the range
- * [<TT>start</TT>, <TT>start + length</TT>) from the UnicodeString object.
- * @param start the offset of the first character to remove
- * @param length the number of characters to remove
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& remove(int32_t start,
- int32_t length = (int32_t)INT32_MAX);
- /**
- * Remove the characters in the range
- * [<TT>start</TT>, <TT>limit</TT>) from the UnicodeString object.
- * @param start the offset of the first character to remove
- * @param limit the offset immediately following the range to remove
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& removeBetween(int32_t start,
- int32_t limit = (int32_t)INT32_MAX);
- /**
- * Retain only the characters in the range
- * [<code>start</code>, <code>limit</code>) from the UnicodeString object.
- * Removes characters before <code>start</code> and at and after <code>limit</code>.
- * @param start the offset of the first character to retain
- * @param limit the offset immediately following the range to retain
- * @return a reference to this
- * @stable ICU 4.4
- */
- inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
- /* Length operations */
- /**
- * Pad the start of this UnicodeString with the character <TT>padChar</TT>.
- * If the length of this UnicodeString is less than targetLength,
- * length() - targetLength copies of padChar will be added to the
- * beginning of this UnicodeString.
- * @param targetLength the desired length of the string
- * @param padChar the character to use for padding. Defaults to
- * space (U+0020)
- * @return TRUE if the text was padded, FALSE otherwise.
- * @stable ICU 2.0
- */
- UBool padLeading(int32_t targetLength,
- UChar padChar = 0x0020);
- /**
- * Pad the end of this UnicodeString with the character <TT>padChar</TT>.
- * If the length of this UnicodeString is less than targetLength,
- * length() - targetLength copies of padChar will be added to the
- * end of this UnicodeString.
- * @param targetLength the desired length of the string
- * @param padChar the character to use for padding. Defaults to
- * space (U+0020)
- * @return TRUE if the text was padded, FALSE otherwise.
- * @stable ICU 2.0
- */
- UBool padTrailing(int32_t targetLength,
- UChar padChar = 0x0020);
- /**
- * Truncate this UnicodeString to the <TT>targetLength</TT>.
- * @param targetLength the desired length of this UnicodeString.
- * @return TRUE if the text was truncated, FALSE otherwise
- * @stable ICU 2.0
- */
- inline UBool truncate(int32_t targetLength);
- /**
- * Trims leading and trailing whitespace from this UnicodeString.
- * @return a reference to this
- * @stable ICU 2.0
- */
- UnicodeString& trim(void);
- /* Miscellaneous operations */
- /**
- * Reverse this UnicodeString in place.
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& reverse(void);
- /**
- * Reverse the range [<TT>start</TT>, <TT>start + length</TT>) in
- * this UnicodeString.
- * @param start the start of the range to reverse
- * @param length the number of characters to to reverse
- * @return a reference to this
- * @stable ICU 2.0
- */
- inline UnicodeString& reverse(int32_t start,
- int32_t length);
- /**
- * Convert the characters in this to UPPER CASE following the conventions of
- * the default locale.
- * @return A reference to this.
- * @stable ICU 2.0
- */
- UnicodeString& toUpper(void);
- /**
- * Convert the characters in this to UPPER CASE following the conventions of
- * a specific locale.
- * @param locale The locale containing the conventions to use.
- * @return A reference to this.
- * @stable ICU 2.0
- */
- UnicodeString& toUpper(const Locale& locale);
- /**
- * Convert the characters in this to lower case following the conventions of
- * the default locale.
- * @return A reference to this.
- * @stable ICU 2.0
- */
- UnicodeString& toLower(void);
- /**
- * Convert the characters in this to lower case following the conventions of
- * a specific locale.
- * @param locale The locale containing the conventions to use.
- * @return A reference to this.
- * @stable ICU 2.0
- */
- UnicodeString& toLower(const Locale& locale);
- #if !UCONFIG_NO_BREAK_ITERATION
- /**
- * Titlecase this string, convenience function using the default locale.
- *
- * Casing is locale-dependent and context-sensitive.
- * Titlecasing uses a break iterator to find the first characters of words
- * that are to be titlecased. It titlecases those characters and lowercases
- * all others.
- *
- * The titlecase break iterator can be provided to customize for arbitrary
- * styles, using rules and dictionaries beyond the standard iterators.
- * It may be more efficient to always provide an iterator to avoid
- * opening and closing one for each string.
- * The standard titlecase iterator for the root locale implements the
- * algorithm of Unicode TR 21.
- *
- * This function uses only the setText(), first() and next() methods of the
- * provided break iterator.
- *
- * @param titleIter A break iterator to find the first characters of words
- * that are to be titlecased.
- * If none is provided (0), then a standard titlecase
- * break iterator is opened.
- * Otherwise the provided iterator is set to the string's text.
- * @return A reference to this.
- * @stable ICU 2.1
- */
- UnicodeString &toTitle(BreakIterator *titleIter);
- /**
- * Titlecase this string.
- *
- * Casing is locale-dependent and context-sensitive.
- * Titlecasing uses a break iterator to find the first characters of words
- * that are to be titlecased. It titlecases those characters and lowercases
- * all others.
- *
- * The titlecase break iterator can be provided to customize for arbitrary
- * styles, using rules and dictionaries beyond the standard iterators.
- * It may be more efficient to always provide an iterator to avoid
- * opening and closing one for each string.
- * The standard titlecase iterator for the root locale implements the
- * algorithm of Unicode TR 21.
- *
- * This function uses only the setText(), first() and next() methods of the
- * provided break iterator.
- *
- * @param titleIter A break iterator to find the first characters of words
- * that are to be titlecased.
- * If none is provided (0), then a standard titlecase
- * break iterator is opened.
- * Otherwise the provided iterator is set to the string's text.
- * @param locale The locale to consider.
- * @return A reference to this.
- * @stable ICU 2.1
- */
- UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
- /**
- * Titlecase this string, with options.
- *
- * Casing is locale-dependent and context-sensitive.
- * Titlecasing uses a break iterator to find the first characters of words
- * that are to be titlecased. It titlecases those characters and lowercases
- * all others. (This can be modified with options.)
- *
- * The titlecase break iterator can be provided to customize for arbitrary
- * styles, using rules and dictionaries beyond the standard iterators.
- * It may be more efficient to always provide an iterator to avoid
- * opening and closing one for each string.
- * The standard titlecase iterator for the root locale implements the
- * algorithm of Unicode TR 21.
- *
- * This function uses only the setText(), first() and next() methods of the
- * provided break iterator.
- *
- * @param titleIter A break iterator to find the first characters of words
- * that are to be titlecased.
- * If none is provided (0), then a standard titlecase
- * break iterator is opened.
- * Otherwise the provided iterator is set to the string's text.
- * @param locale The locale to consider.
- * @param options Options bit set, see ucasemap_open().
- * @return A reference to this.
- * @see U_TITLECASE_NO_LOWERCASE
- * @see U_TITLECASE_NO_BREAK_ADJUSTMENT
- * @see ucasemap_open
- * @stable ICU 3.8
- */
- UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
- #endif
- /**
- * Case-fold the characters in this string.
- * Case-folding is locale-independent and not context-sensitive,
- * but there is an option for whether to include or exclude mappings for dotted I
- * and dotless i that are marked with 'I' in CaseFolding.txt.
- * The result may be longer or shorter than the original.
- *
- * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
- * @return A reference to this.
- * @stable ICU 2.0
- */
- UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
- //========================================
- // Access to the internal buffer
- //========================================
- /**
- * 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.
- *
- * @param 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
- * @return a writable pointer to the internal string buffer,
- * or 0 if an error occurs (nested calls, out of memory)
- *
- * @see releaseBuffer
- * @see getTerminatedBuffer()
- * @stable ICU 2.0
- */
- UChar *getBuffer(int32_t minCapacity);
- /**
- * Release a read/write buffer on a UnicodeString object with an
- * "open" getBuffer(minCapacity).
- * This function must be called in a matched pair with getBuffer(minCapacity).
- * releaseBuffer(newLength) must be called if and only if a getBuffer(minCapacity) is "open".
- *
- * It will set the string length to newLength, at most to the current capacity.
- * If newLength==-1 then it will set the length according to the
- * first NUL in the buffer, or to the capacity if there is no NUL.
- *
- * After calling releaseBuffer(newLength) the UnicodeString is back to normal operation.
- *
- * @param newLength the new length of the UnicodeString object;
- * defaults to the current capacity if newLength is greater than that;
- * if newLength==-1, it defaults to u_strlen(buffer) but not more than
- * the current capacity of the string
- *
- * @see getBuffer(int32_t minCapacity)
- * @stable ICU 2.0
- */
- void releaseBuffer(int32_t newLength=-1);
- /**
- * Get a read-only pointer to the internal buffer.
- * This can be called at any time on a valid UnicodeString.
- *
- * It returns 0 if the string is bogus, or
- * during an "open" getBuffer(minCapacity).
- *
- * It can be called as many times as desired.
- * The pointer that it returns will remain valid until the UnicodeString object is modified,
- * at which time the pointer is semantically invalidated and must not be used any more.
- *
- * The capacity of the buffer can be determined with getCapacity().
- * The part after length() may or may not be initialized and valid,
- * depending on the history of the UnicodeString object.
- *
- * The buffer contents is (probably) not NUL-terminated.
- * You can check if it is with
- * <code>(s.length()<s.getCapacity() && buffer[s.length()]==0)</code>.
- * (See getTerminatedBuffer().)
- *
- * The buffer may reside in read-only memory. Its contents must not
- * be modified.
- *
- * @return a read-only pointer to the internal string buffer,
- * or 0 if the string is empty or bogus
- *
- * @see getBuffer(int32_t minCapacity)
- * @see getTerminatedBuffer()
- * @stable ICU 2.0
- */
- inline const UChar *getBuffer() const;
- /**
- * Get a read-only pointer to the internal buffer,
- * making sure that it is NUL-terminated.
- * This can be called at any time on a valid UnicodeString.
- *
- * It returns 0 if the string is bogus, or
- * during an "open" getBuffer(minCapacity), or if the buffer cannot
- * be NUL-terminated (because memory allocation failed).
- *
- * It can be called as many times as desired.
- * The pointer that it returns will remain valid until the UnicodeString object is modified,
- * at which time the pointer is semantically invalidated and must not be used any more.
- *
- * The capacity of the buffer can be determined with getCapacity().
- * The part after length()+1 may or may not be initialized and valid,
- * depending on the history of the UnicodeString object.
- *
- * The buffer contents is guaranteed to be NUL-terminated.
- * getTerminatedBuffer() may reallocate the buffer if a terminating NUL
- * is written.
- * For this reason, this function is not const, unlike getBuffer().
- * Note that a UnicodeString may also contain NUL characters as part of its contents.
- *
- * The buffer may reside in read-only memory. Its contents must not
- * be modified.
- *
- * @return a read-only pointer to the internal string buffer,
- * or 0 if the string is empty or bogus
- *
- * @see getBuffer(int32_t minCapacity)
- * @see getBuffer()
- * @stable ICU 2.2
- */
- inline const UChar *getTerminatedBuffer();
- //========================================
- // Constructors
- //========================================
- /** Construct an empty UnicodeString.
- * @stable ICU 2.0
- */
- UnicodeString();
- /**
- * Construct a UnicodeString with capacity to hold <TT>capacity</TT> UChars
- * @param capacity the number of UChars this UnicodeString should hold
- * before a resize is necessary; if count is greater than 0 and count
- * code points c take up more space than capacity, then capacity is adjusted
- * accordingly.
- * @param c is used to initially fill the string
- * @param count specifies how many code points c are to be written in the
- * string
- * @stable ICU 2.0
- */
- UnicodeString(int32_t capacity, UChar32 c, int32_t count);
- /**
- * Single UChar (code unit) constructor.
- * @param ch the character to place in the UnicodeString
- * @stable ICU 2.0
- */
- UnicodeString(UChar ch);
- /**
- * Single UChar32 (code point) constructor.
- * @param ch the character to place in the UnicodeString
- * @stable ICU 2.0
- */
- UnicodeString(UChar32 ch);
- /**
- * UChar* constructor.
- * @param text The characters to place in the UnicodeString. <TT>text</TT>
- * must be NULL (U+0000) terminated.
- * @stable ICU 2.0
- */
- UnicodeString(const UChar *text);
- /**
- * UChar* constructor.
- * @param text The characters to place in the UnicodeString.
- * @param textLength The number of Unicode characters in <TT>text</TT>
- * to copy.
- * @stable ICU 2.0
- */
- UnicodeString(const UChar *text,
- int32_t textLength);
- /**
- * Readonly-aliasing UChar* constructor.
- * The text will be used for the UnicodeString object, but
- * it will not be released when the UnicodeString is destroyed.
- * This has copy-on-write semantics:
- * When the string is modified, then the buffer is first copied into
- * newly allocated memory.
- * The aliased buffer is never modified.
- * In an assignment to another UnicodeString, the text will be aliased again,
- * so that both strings then alias the same readonly-text.
- *
- * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
- * This must be true if <code>textLength==-1</code>.
- * @param text The characters to alias for the UnicodeString.
- * @param textLength The number of Unicode characters in <code>text</code> to alias.
- * If -1, then this constructor will determine the length
- * by calling <code>u_strlen()</code>.
- * @stable ICU 2.0
- */
- UnicodeString(UBool isTerminated,
- const UChar *text,
- int32_t textLength);
- /**
- * Writable-aliasing UChar* constructor.
- * The text will be used for the UnicodeString object, but
- * it will not be released when the UnicodeString is destroyed.
- * This has write-through semantics:
- * For as long as the capacity of the buffer is sufficient, write operations
- * will directly affect the buffer. When more capacity is necessary, then
- * a new buffer will be allocated and the contents copied as with regularly
- * constructed strings.
- * In an assignment to another UnicodeString, the buffer will be copied.
- * The extract(UChar *dst) function detects whether the dst pointer is the same
- * as the string buffer itself and will in this case not copy the contents.
- *
- * @param buffer The characters to alias for the UnicodeString.
- * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
- * @param buffCapacity The size of <code>buffer</code> in UChars.
- * @stable ICU 2.0
- */
- UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
- #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
- /**
- * char* constructor.
- * @param codepageData an array of bytes, null-terminated,
- * in the platform's default codepage.
- * @stable ICU 2.0
- */
- UnicodeString(const char *codepageData);
- /**
- * char* constructor.
- * @param codepageData an array of bytes in the platform's default codepage.
- * @param dataLength The number of bytes in <TT>codepageData</TT>.
- * @stable ICU 2.0
- */
- UnicodeString(const char *codepageData, int32_t dataLength);
- #endif
- #if !UCONFIG_NO_CONVERSION
- /**
- * char* constructor.
- * @param codepageData an array of bytes, null-terminated
- * @param codepage the encoding of <TT>codepageData</TT>. The special
- * value 0 for <TT>codepage</TT> indicates that the text is in the
- * platform's default codepage.
- *
- * If <code>codepage</code> is an empty string (<code>""</code>),
- * then a simple conversion is performed on the codepage-invariant
- * subset ("invariant characters") of the platform encoding. See utypes.h.
- * Recommendation: For invariant-character strings use the constructor
- * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
- * because it avoids object code dependencies of UnicodeString on
- * the conversion code.
- *
- * @stable ICU 2.0
- */
- UnicodeString(const char *codepageData, const char *codepage);
- /**
- * char* constructor.
- * @param codepageData an array of bytes.
- * @param dataLength The number of bytes in <TT>codepageData</TT>.
- * @param codepage the encoding of <TT>codepageData</TT>. The special
- * value 0 for <TT>codepage</TT> indicates that the text is in the
- * platform's default codepage.
- * If <code>codepage</code> is an empty string (<code>""</code>),
- * then a simple conversion is performed on the codepage-invariant
- * subset ("invariant characters") of the platform encoding. See utypes.h.
- * Recommendation: For invariant-character strings use the constructor
- * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
- * because it avoids object code dependencies of UnicodeString on
- * the conversion code.
- *
- * @stable ICU 2.0
- */
- UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
- /**
- * char * / UConverter constructor.
- * This constructor uses an existing UConverter object to
- * convert the codepage string to Unicode and construct a UnicodeString
- * from that.
- *
- * The converter is reset at first.
- * If the error code indicates a failure before this constructor is called,
- * or if an error occurs during conversion or construction,
- * then the string will be bogus.
- *
- * This function avoids the overhead of opening and closing a converter if
- * multiple strings are constructed.
- *
- * @param src input codepage string
- * @param srcLength length of the input string, can be -1 for NUL-terminated strings
- * @param cnv converter object (ucnv_resetToUnicode() will be called),
- * can be NULL for the default converter
- * @param errorCode normal ICU error code
- * @stable ICU 2.0
- */
- UnicodeString(
- const char *src, int32_t srcLength,
- UConverter *cnv,
- UErrorCode &errorCode);
- #endif
- /**
- * Constructs a Unicode string from an invariant-character char * string.
- * About invariant characters see utypes.h.
- * This constructor has no runtime dependency on conversion code and is
- * therefore recommended over ones taking a charset name string
- * (where the empty string "" indicates invariant-character conversion).
- *
- * Use the macro US_INV as the third, signature-distinguishing parameter.
- *
- * For example:
- * \code
- * void fn(const char *s) {
- * UnicodeString ustr(s, -1, US_INV);
- * // use ustr ...
- * }
- * \endcode
- *
- * @param src String using only invariant characters.
- * @param length Length of src, or -1 if NUL-terminated.
- * @param inv Signature-distinguishing paramater, use US_INV.
- *
- * @see US_INV
- * @stable ICU 3.2
- */
- UnicodeString(const char *src, int32_t length, enum EInvariant inv);
- /**
- * Copy constructor.
- * @param that The UnicodeString object to copy.
- * @stable ICU 2.0
- */
- UnicodeString(const UnicodeString& that);
- /**
- * 'Substring' constructor from tail of source string.
- * @param src The UnicodeString object to copy.
- * @param srcStart The offset into <tt>src</tt> at which to start copying.
- * @stable ICU 2.2
- */
- UnicodeString(const UnicodeString& src, int32_t srcStart);
- /**
- * 'Substring' constructor from subrange of source string.
- * @param src The UnicodeString object to copy.
- * @param srcStart The offset into <tt>src</tt> at which to start copying.
- * @param srcLength The number of characters from <tt>src</tt> to copy.
- * @stable ICU 2.2
- */
- UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
- /**
- * Clone this object, an instance of a subclass of Replaceable.
- * Clones can be used concurrently in multiple threads.
- * If a subclass does not implement clone(), or if an error occurs,
- * then NULL is returned.
- * The clone functions in all subclasses return a pointer to a Replaceable
- * because some compilers do not support covariant (same-as-this)
- * return types; cast to the appropriate subclass if necessary.
- * The caller must delete the clone.
- *
- * @return a clone of this object
- *
- * @see Replaceable::clone
- * @see getDynamicClassID
- * @stable ICU 2.6
- */
- virtual Replaceable *clone() const;
- /** Destructor.
- * @stable ICU 2.0
- */
- virtual ~UnicodeString();
- /**
- * Create a UnicodeString from a UTF-8 string.
- * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
- * Calls u_strFromUTF8WithSub().
- *
- * @param utf8 UTF-8 input string.
- * Note that a StringPiece can be implicitly constructed
- * from a std::string or a NUL-terminated const char * string.
- * @return A UnicodeString with equivalent UTF-16 contents.
- * @see toUTF8
- * @see toUTF8String
- * @stable ICU 4.2
- */
- static UnicodeString fromUTF8(const StringPiece &utf8);
- /**
- * Create a UnicodeString from a UTF-32 string.
- * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
- * Calls u_strFromUTF32WithSub().
- *
- * @param utf32 UTF-32 input string. Must not be NULL.
- * @param length Length of the input string, or -1 if NUL-terminated.
- * @return A UnicodeString with equivalent UTF-16 contents.
- * @see toUTF32
- * @stable ICU 4.2
- */
- static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
- /* Miscellaneous operations */
- /**
- * Unescape a string of characters and return a string containing
- * the result. The following escape sequences are recognized:
- *
- * \\uhhhh 4 hex digits; h in [0-9A-Fa-f]
- * \\Uhhhhhhhh 8 hex digits
- * \\xhh 1-2 hex digits
- * \\ooo 1-3 octal digits; o in [0-7]
- * \\cX control-X; X is masked with 0x1F
- *
- * as well as the standard ANSI C escapes:
- *
- * \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A,
- * \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B,
- * \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C
- *
- * Anything else following a backslash is generically escaped. For
- * example, "[a\\-z]" returns "[a-z]".
- *
- * If an escape sequence is ill-formed, this method returns an empty
- * string. An example of an ill-formed sequence is "\\u" followed by
- * fewer than 4 hex digits.
- *
- * This function is similar to u_unescape() but not identical to it.
- * The latter takes a source char*, so it does escape recognition
- * and also invariant conversion.
- *
- * @return a string with backslash escapes interpreted, or an
- * empty string on error.
- * @see UnicodeString#unescapeAt()
- * @see u_unescape()
- * @see u_unescapeAt()
- * @stable ICU 2.0
- */
- UnicodeString unescape() const;
- /**
- * Unescape a single escape sequence and return the represented
- * character. See unescape() for a listing of the recognized escape
- * sequences. The character at offset-1 is assumed (without
- * checking) to be a backslash. If the escape sequence is
- * ill-formed, or the offset is out of range, (UChar32)0xFFFFFFFF is
- * returned.
- *
- * @param offset an input output parameter. On input, it is the
- * offset into this string where the escape sequence is located,
- * after the initial backslash. On output, it is advanced after the
- * last character parsed. On error, it is not advanced at all.
- * @return the character represented by the escape sequence at
- * offset, or (UChar32)0xFFFFFFFF on error.
- * @see UnicodeString#unescape()
- * @see u_unescape()
- * @see u_unescapeAt()
- * @stable ICU 2.0
- */
- UChar32 unescapeAt(int32_t &offset) const;
- /**
- * ICU "poor man's RTTI", returns a UClassID for this class.
- *
- * @stable ICU 2.2
- */
- static UClassID U_EXPORT2 getStaticClassID();
- /**
- * ICU "poor man's RTTI", returns a UClassID for the actual class.
- *
- * @stable ICU 2.2
- */
- virtual UClassID getDynamicClassID() const;
- //========================================
- // Implementation methods
- //========================================
- protected:
- /**
- * Implement Replaceable::getLength() (see jitterbug 1027).
- * @stable ICU 2.4
- */
- virtual int32_t getLength() const;
- /**
- * The change in Replaceable to use virtual getCharAt() allows
- * UnicodeString::charAt() to be inline again (see jitterbug 709).
- * @stable ICU 2.4
- */
- virtual UChar getCharAt(int32_t offset) const;
- /**
- * The change in Replaceable to use virtual getChar32At() allows
- * UnicodeString::char32At() to be inline again (see jitterbug 709).
- * @stable ICU 2.4
- */
- virtual UChar32 getChar32At(int32_t offset) const;
- private:
- // For char* constructors. Could be made public.
- UnicodeString &setToUTF8(const StringPiece &utf8);
- // For extract(char*).
- // We could make a toUTF8(target, capacity, errorCode) public but not
- // this version: New API will be cleaner if we make callers create substrings
- // rather than having start+length on every method,
- // and it should take a UErrorCode&.
- int32_t
- toUTF8(int32_t start, int32_t len,
- char *target, int32_t capacity) const;
- inline int8_t
- doCompare(int32_t start,
- int32_t length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const;
- int8_t doCompare(int32_t start,
- int32_t length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const;
- inline int8_t
- doCompareCodePointOrder(int32_t start,
- int32_t length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const;
- int8_t doCompareCodePointOrder(int32_t start,
- int32_t length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const;
- inline int8_t
- doCaseCompare(int32_t start,
- int32_t length,
- const UnicodeString &srcText,
- int32_t srcStart,
- int32_t srcLength,
- uint32_t options) const;
- int8_t
- doCaseCompare(int32_t start,
- int32_t length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength,
- uint32_t options) const;
- int32_t doIndexOf(UChar c,
- int32_t start,
- int32_t length) const;
- int32_t doIndexOf(UChar32 c,
- int32_t start,
- int32_t length) const;
- int32_t doLastIndexOf(UChar c,
- int32_t start,
- int32_t length) const;
- int32_t doLastIndexOf(UChar32 c,
- int32_t start,
- int32_t length) const;
- void doExtract(int32_t start,
- int32_t length,
- UChar *dst,
- int32_t dstStart) const;
- inline void doExtract(int32_t start,
- int32_t length,
- UnicodeString& target) const;
- inline UChar doCharAt(int32_t offset) const;
- UnicodeString& doReplace(int32_t start,
- int32_t length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength);
- UnicodeString& doReplace(int32_t start,
- int32_t length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength);
- UnicodeString& doReverse(int32_t start,
- int32_t length);
- // calculate hash code
- int32_t doHashCode(void) const;
- // get pointer to start of array
- // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
- inline UChar* getArrayStart(void);
- inline const UChar* getArrayStart(void) const;
- // A UnicodeString object (not necessarily its current buffer)
- // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
- inline UBool isWritable() const;
- // Is the current buffer writable?
- inline UBool isBufferWritable() const;
- // None of the following does releaseArray().
- inline void setLength(int32_t len); // sets only fShortLength and fLength
- inline void setToEmpty(); // sets fFlags=kShortString
- inline void setArray(UChar *array, int32_t len, int32_t capacity); // does not set fFlags
- // allocate the array; result may be fStackBuffer
- // sets refCount to 1 if appropriate
- // sets fArray, fCapacity, and fFlags
- // returns boolean for success or failure
- UBool allocate(int32_t capacity);
- // release the array if owned
- void releaseArray(void);
- // turn a bogus string into an empty one
- void unBogus();
- // implements assigment operator, copy constructor, and fastCopyFrom()
- UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
- // Pin start and limit to acceptable values.
- inline void pinIndex(int32_t& start) const;
- inline void pinIndices(int32_t& start,
- int32_t& length) const;
- #if !UCONFIG_NO_CONVERSION
- /* Internal extract() using UConverter. */
- int32_t doExtract(int32_t start, int32_t length,
- char *dest, int32_t destCapacity,
- UConverter *cnv,
- UErrorCode &errorCode) const;
- /*
- * Real constructor for converting from codepage data.
- * It assumes that it is called with !fRefCounted.
- *
- * If <code>codepage==0</code>, then the default converter
- * is used for the platform encoding.
- * If <code>codepage</code> is an empty string (<code>""</code>),
- * then a simple conversion is performed on the codepage-invariant
- * subset ("invariant characters") of the platform encoding. See utypes.h.
- */
- void doCodepageCreate(const char *codepageData,
- int32_t dataLength,
- const char *codepage);
- /*
- * Worker function for creating a UnicodeString from
- * a codepage string using a UConverter.
- */
- void
- doCodepageCreate(const char *codepageData,
- int32_t dataLength,
- UConverter *converter,
- UErrorCode &status);
- #endif
- /*
- * This function is called when write access to the array
- * is necessary.
- *
- * We need to make a copy of the array if
- * the buffer is read-only, or
- * the buffer is refCounted (shared), and refCount>1, or
- * the buffer is too small.
- *
- * Return FALSE if memory could not be allocated.
- */
- UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
- int32_t growCapacity = -1,
- UBool doCopyArray = TRUE,
- int32_t **pBufferToDelete = 0,
- UBool forceClone = FALSE);
- // common function for case mappings
- UnicodeString &
- caseMap(BreakIterator *titleIter,
- const char *locale,
- uint32_t options,
- int32_t toWhichCase);
- // ref counting
- void addRef(void);
- int32_t removeRef(void);
- int32_t refCount(void) const;
- // constants
- enum {
- // Set the stack buffer size so that sizeof(UnicodeString) is a multiple of sizeof(pointer):
- // 32-bit pointers: 4+1+1+13*2 = 32 bytes
- // 64-bit pointers: 8+1+1+15*2 = 40 bytes
- US_STACKBUF_SIZE= sizeof(void *)==4 ? 13 : 15, // Size of stack buffer for small strings
- kInvalidUChar=0xffff, // invalid UChar index
- kGrowSize=128, // grow size for this buffer
- kInvalidHashCode=0, // invalid hash code
- kEmptyHashCode=1, // hash code for empty string
- // bit flag values for fFlags
- kIsBogus=1, // this string is bogus, i.e., not valid or NULL
- kUsingStackBuffer=2,// fArray==fStackBuffer
- kRefCounted=4, // there is a refCount field before the characters in fArray
- kBufferIsReadonly=8,// do not write to this buffer
- kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
- // and releaseBuffer(newLength) must be called
- // combined values for convenience
- kShortString=kUsingStackBuffer,
- kLongString=kRefCounted,
- kReadonlyAlias=kBufferIsReadonly,
- kWritableAlias=0
- };
- friend class StringThreadTest;
- union StackBufferOrFields; // forward declaration necessary before friend declaration
- friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
- /*
- * The following are all the class fields that are stored
- * in each UnicodeString object.
- * Note that UnicodeString has virtual functions,
- * therefore there is an implicit vtable pointer
- * as the first real field.
- * The fields should be aligned such that no padding is
- * necessary, mostly by having larger types first.
- * On 32-bit machines, the size should be 32 bytes,
- * on 64-bit machines (8-byte pointers), it should be 40 bytes.
- */
- // (implicit) *vtable;
- int8_t fShortLength; // 0..127: length <0: real length is in fUnion.fFields.fLength
- uint8_t fFlags; // bit flags: see constants above
- union StackBufferOrFields {
- // fStackBuffer is used iff (fFlags&kUsingStackBuffer)
- // else fFields is used
- UChar fStackBuffer [US_STACKBUF_SIZE]; // buffer for small strings
- struct {
- uint16_t fPadding; // align the following field at 8B (32b pointers) or 12B (64b)
- int32_t fLength; // number of characters in fArray if >127; else undefined
- UChar *fArray; // the Unicode data (aligned at 12B (32b pointers) or 16B (64b))
- int32_t fCapacity; // sizeof fArray
- } fFields;
- } fUnion;
- };
- /**
- * Create a new UnicodeString with the concatenation of two others.
- *
- * @param s1 The first string to be copied to the new one.
- * @param s2 The second string to be copied to the new one, after s1.
- * @return UnicodeString(s1).append(s2)
- * @stable ICU 2.8
- */
- U_COMMON_API UnicodeString U_EXPORT2
- operator+ (const UnicodeString &s1, const UnicodeString &s2);
- //========================================
- // Inline members
- //========================================
- //========================================
- // Privates
- //========================================
- inline void
- UnicodeString::pinIndex(int32_t& start) const
- {
- // pin index
- if(start < 0) {
- start = 0;
- } else if(start > length()) {
- start = length();
- }
- }
- inline void
- UnicodeString::pinIndices(int32_t& start,
- int32_t& _length) const
- {
- // pin indices
- int32_t len = length();
- if(start < 0) {
- start = 0;
- } else if(start > len) {
- start = len;
- }
- if(_length < 0) {
- _length = 0;
- } else if(_length > (len - start)) {
- _length = (len - start);
- }
- }
- inline UChar*
- UnicodeString::getArrayStart()
- { return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; }
- inline const UChar*
- UnicodeString::getArrayStart() const
- { return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; }
- //========================================
- // Read-only implementation methods
- //========================================
- inline int32_t
- UnicodeString::length() const
- { return fShortLength>=0 ? fShortLength : fUnion.fFields.fLength; }
- inline int32_t
- UnicodeString::getCapacity() const
- { return (fFlags&kUsingStackBuffer) ? US_STACKBUF_SIZE : fUnion.fFields.fCapacity; }
- inline int32_t
- UnicodeString::hashCode() const
- { return doHashCode(); }
- inline UBool
- UnicodeString::isBogus() const
- { return (UBool)(fFlags & kIsBogus); }
- inline UBool
- UnicodeString::isWritable() const
- { return (UBool)!(fFlags&(kOpenGetBuffer|kIsBogus)); }
- inline UBool
- UnicodeString::isBufferWritable() const
- {
- return (UBool)(
- !(fFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
- (!(fFlags&kRefCounted) || refCount()==1));
- }
- inline const UChar *
- UnicodeString::getBuffer() const {
- if(fFlags&(kIsBogus|kOpenGetBuffer)) {
- return 0;
- } else if(fFlags&kUsingStackBuffer) {
- return fUnion.fStackBuffer;
- } else {
- return fUnion.fFields.fArray;
- }
- }
- //========================================
- // Read-only alias methods
- //========================================
- inline int8_t
- UnicodeString::doCompare(int32_t start,
- int32_t thisLength,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const
- {
- if(srcText.isBogus()) {
- return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
- } else {
- srcText.pinIndices(srcStart, srcLength);
- return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
- }
- }
- inline UBool
- UnicodeString::operator== (const UnicodeString& text) const
- {
- if(isBogus()) {
- return text.isBogus();
- } else {
- int32_t len = length(), textLength = text.length();
- return
- !text.isBogus() &&
- len == textLength &&
- doCompare(0, len, text, 0, textLength) == 0;
- }
- }
- inline UBool
- UnicodeString::operator!= (const UnicodeString& text) const
- { return (! operator==(text)); }
- inline UBool
- UnicodeString::operator> (const UnicodeString& text) const
- { return doCompare(0, length(), text, 0, text.length()) == 1; }
- inline UBool
- UnicodeString::operator< (const UnicodeString& text) const
- { return doCompare(0, length(), text, 0, text.length()) == -1; }
- inline UBool
- UnicodeString::operator>= (const UnicodeString& text) const
- { return doCompare(0, length(), text, 0, text.length()) != -1; }
- inline UBool
- UnicodeString::operator<= (const UnicodeString& text) const
- { return doCompare(0, length(), text, 0, text.length()) != 1; }
- inline int8_t
- UnicodeString::compare(const UnicodeString& text) const
- { return doCompare(0, length(), text, 0, text.length()); }
- inline int8_t
- UnicodeString::compare(int32_t start,
- int32_t _length,
- const UnicodeString& srcText) const
- { return doCompare(start, _length, srcText, 0, srcText.length()); }
- inline int8_t
- UnicodeString::compare(const UChar *srcChars,
- int32_t srcLength) const
- { return doCompare(0, length(), srcChars, 0, srcLength); }
- inline int8_t
- UnicodeString::compare(int32_t start,
- int32_t _length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const
- { return doCompare(start, _length, srcText, srcStart, srcLength); }
- inline int8_t
- UnicodeString::compare(int32_t start,
- int32_t _length,
- const UChar *srcChars) const
- { return doCompare(start, _length, srcChars, 0, _length); }
- inline int8_t
- UnicodeString::compare(int32_t start,
- int32_t _length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const
- { return doCompare(start, _length, srcChars, srcStart, srcLength); }
- inline int8_t
- UnicodeString::compareBetween(int32_t start,
- int32_t limit,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLimit) const
- { return doCompare(start, limit - start,
- srcText, srcStart, srcLimit - srcStart); }
- inline int8_t
- UnicodeString::doCompareCodePointOrder(int32_t start,
- int32_t thisLength,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const
- {
- if(srcText.isBogus()) {
- return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
- } else {
- srcText.pinIndices(srcStart, srcLength);
- return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
- }
- }
- inline int8_t
- UnicodeString::compareCodePointOrder(const UnicodeString& text) const
- { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
- inline int8_t
- UnicodeString::compareCodePointOrder(int32_t start,
- int32_t _length,
- const UnicodeString& srcText) const
- { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
- inline int8_t
- UnicodeString::compareCodePointOrder(const UChar *srcChars,
- int32_t srcLength) const
- { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
- inline int8_t
- UnicodeString::compareCodePointOrder(int32_t start,
- int32_t _length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const
- { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
- inline int8_t
- UnicodeString::compareCodePointOrder(int32_t start,
- int32_t _length,
- const UChar *srcChars) const
- { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
- inline int8_t
- UnicodeString::compareCodePointOrder(int32_t start,
- int32_t _length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const
- { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
- inline int8_t
- UnicodeString::compareCodePointOrderBetween(int32_t start,
- int32_t limit,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLimit) const
- { return doCompareCodePointOrder(start, limit - start,
- srcText, srcStart, srcLimit - srcStart); }
- inline int8_t
- UnicodeString::doCaseCompare(int32_t start,
- int32_t thisLength,
- const UnicodeString &srcText,
- int32_t srcStart,
- int32_t srcLength,
- uint32_t options) const
- {
- if(srcText.isBogus()) {
- return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
- } else {
- srcText.pinIndices(srcStart, srcLength);
- return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
- }
- }
- inline int8_t
- UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
- return doCaseCompare(0, length(), text, 0, text.length(), options);
- }
- inline int8_t
- UnicodeString::caseCompare(int32_t start,
- int32_t _length,
- const UnicodeString &srcText,
- uint32_t options) const {
- return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
- }
- inline int8_t
- UnicodeString::caseCompare(const UChar *srcChars,
- int32_t srcLength,
- uint32_t options) const {
- return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
- }
- inline int8_t
- UnicodeString::caseCompare(int32_t start,
- int32_t _length,
- const UnicodeString &srcText,
- int32_t srcStart,
- int32_t srcLength,
- uint32_t options) const {
- return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
- }
- inline int8_t
- UnicodeString::caseCompare(int32_t start,
- int32_t _length,
- const UChar *srcChars,
- uint32_t options) const {
- return doCaseCompare(start, _length, srcChars, 0, _length, options);
- }
- inline int8_t
- UnicodeString::caseCompare(int32_t start,
- int32_t _length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength,
- uint32_t options) const {
- return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
- }
- inline int8_t
- UnicodeString::caseCompareBetween(int32_t start,
- int32_t limit,
- const UnicodeString &srcText,
- int32_t srcStart,
- int32_t srcLimit,
- uint32_t options) const {
- return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
- }
- inline int32_t
- UnicodeString::indexOf(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength,
- int32_t start,
- int32_t _length) const
- {
- if(!srcText.isBogus()) {
- srcText.pinIndices(srcStart, srcLength);
- if(srcLength > 0) {
- return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
- }
- }
- return -1;
- }
- inline int32_t
- UnicodeString::indexOf(const UnicodeString& text) const
- { return indexOf(text, 0, text.length(), 0, length()); }
- inline int32_t
- UnicodeString::indexOf(const UnicodeString& text,
- int32_t start) const {
- pinIndex(start);
- return indexOf(text, 0, text.length(), start, length() - start);
- }
- inline int32_t
- UnicodeString::indexOf(const UnicodeString& text,
- int32_t start,
- int32_t _length) const
- { return indexOf(text, 0, text.length(), start, _length); }
- inline int32_t
- UnicodeString::indexOf(const UChar *srcChars,
- int32_t srcLength,
- int32_t start) const {
- pinIndex(start);
- return indexOf(srcChars, 0, srcLength, start, length() - start);
- }
- inline int32_t
- UnicodeString::indexOf(const UChar *srcChars,
- int32_t srcLength,
- int32_t start,
- int32_t _length) const
- { return indexOf(srcChars, 0, srcLength, start, _length); }
- inline int32_t
- UnicodeString::indexOf(UChar c,
- int32_t start,
- int32_t _length) const
- { return doIndexOf(c, start, _length); }
- inline int32_t
- UnicodeString::indexOf(UChar32 c,
- int32_t start,
- int32_t _length) const
- { return doIndexOf(c, start, _length); }
- inline int32_t
- UnicodeString::indexOf(UChar c) const
- { return doIndexOf(c, 0, length()); }
- inline int32_t
- UnicodeString::indexOf(UChar32 c) const
- { return indexOf(c, 0, length()); }
- inline int32_t
- UnicodeString::indexOf(UChar c,
- int32_t start) const {
- pinIndex(start);
- return doIndexOf(c, start, length() - start);
- }
- inline int32_t
- UnicodeString::indexOf(UChar32 c,
- int32_t start) const {
- pinIndex(start);
- return indexOf(c, start, length() - start);
- }
- inline int32_t
- UnicodeString::lastIndexOf(const UChar *srcChars,
- int32_t srcLength,
- int32_t start,
- int32_t _length) const
- { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
- inline int32_t
- UnicodeString::lastIndexOf(const UChar *srcChars,
- int32_t srcLength,
- int32_t start) const {
- pinIndex(start);
- return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
- }
- inline int32_t
- UnicodeString::lastIndexOf(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength,
- int32_t start,
- int32_t _length) const
- {
- if(!srcText.isBogus()) {
- srcText.pinIndices(srcStart, srcLength);
- if(srcLength > 0) {
- return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
- }
- }
- return -1;
- }
- inline int32_t
- UnicodeString::lastIndexOf(const UnicodeString& text,
- int32_t start,
- int32_t _length) const
- { return lastIndexOf(text, 0, text.length(), start, _length); }
- inline int32_t
- UnicodeString::lastIndexOf(const UnicodeString& text,
- int32_t start) const {
- pinIndex(start);
- return lastIndexOf(text, 0, text.length(), start, length() - start);
- }
- inline int32_t
- UnicodeString::lastIndexOf(const UnicodeString& text) const
- { return lastIndexOf(text, 0, text.length(), 0, length()); }
- inline int32_t
- UnicodeString::lastIndexOf(UChar c,
- int32_t start,
- int32_t _length) const
- { return doLastIndexOf(c, start, _length); }
- inline int32_t
- UnicodeString::lastIndexOf(UChar32 c,
- int32_t start,
- int32_t _length) const {
- return doLastIndexOf(c, start, _length);
- }
- inline int32_t
- UnicodeString::lastIndexOf(UChar c) const
- { return doLastIndexOf(c, 0, length()); }
- inline int32_t
- UnicodeString::lastIndexOf(UChar32 c) const {
- return lastIndexOf(c, 0, length());
- }
- inline int32_t
- UnicodeString::lastIndexOf(UChar c,
- int32_t start) const {
- pinIndex(start);
- return doLastIndexOf(c, start, length() - start);
- }
- inline int32_t
- UnicodeString::lastIndexOf(UChar32 c,
- int32_t start) const {
- pinIndex(start);
- return lastIndexOf(c, start, length() - start);
- }
- inline UBool
- UnicodeString::startsWith(const UnicodeString& text) const
- { return compare(0, text.length(), text, 0, text.length()) == 0; }
- inline UBool
- UnicodeString::startsWith(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const
- { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
- inline UBool
- UnicodeString::startsWith(const UChar *srcChars,
- int32_t srcLength) const
- { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
- inline UBool
- UnicodeString::startsWith(const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const
- { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
- inline UBool
- UnicodeString::endsWith(const UnicodeString& text) const
- { return doCompare(length() - text.length(), text.length(),
- text, 0, text.length()) == 0; }
- inline UBool
- UnicodeString::endsWith(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength) const {
- srcText.pinIndices(srcStart, srcLength);
- return doCompare(length() - srcLength, srcLength,
- srcText, srcStart, srcLength) == 0;
- }
- inline UBool
- UnicodeString::endsWith(const UChar *srcChars,
- int32_t srcLength) const {
- if(srcLength < 0) {
- srcLength = u_strlen(srcChars);
- }
- return doCompare(length() - srcLength, srcLength,
- srcChars, 0, srcLength) == 0;
- }
- inline UBool
- UnicodeString::endsWith(const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const {
- if(srcLength < 0) {
- srcLength = u_strlen(srcChars + srcStart);
- }
- return doCompare(length() - srcLength, srcLength,
- srcChars, srcStart, srcLength) == 0;
- }
- //========================================
- // replace
- //========================================
- inline UnicodeString&
- UnicodeString::replace(int32_t start,
- int32_t _length,
- const UnicodeString& srcText)
- { return doReplace(start, _length, srcText, 0, srcText.length()); }
- inline UnicodeString&
- UnicodeString::replace(int32_t start,
- int32_t _length,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength)
- { return doReplace(start, _length, srcText, srcStart, srcLength); }
- inline UnicodeString&
- UnicodeString::replace(int32_t start,
- int32_t _length,
- const UChar *srcChars,
- int32_t srcLength)
- { return doReplace(start, _length, srcChars, 0, srcLength); }
- inline UnicodeString&
- UnicodeString::replace(int32_t start,
- int32_t _length,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength)
- { return doReplace(start, _length, srcChars, srcStart, srcLength); }
- inline UnicodeString&
- UnicodeString::replace(int32_t start,
- int32_t _length,
- UChar srcChar)
- { return doReplace(start, _length, &srcChar, 0, 1); }
- inline UnicodeString&
- UnicodeString::replace(int32_t start,
- int32_t _length,
- UChar32 srcChar) {
- UChar buffer[U16_MAX_LENGTH];
- int32_t count = 0;
- UBool isError = FALSE;
- U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
- return doReplace(start, _length, buffer, 0, count);
- }
- inline UnicodeString&
- UnicodeString::replaceBetween(int32_t start,
- int32_t limit,
- const UnicodeString& srcText)
- { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
- inline UnicodeString&
- UnicodeString::replaceBetween(int32_t start,
- int32_t limit,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLimit)
- { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
- inline UnicodeString&
- UnicodeString::findAndReplace(const UnicodeString& oldText,
- const UnicodeString& newText)
- { return findAndReplace(0, length(), oldText, 0, oldText.length(),
- newText, 0, newText.length()); }
- inline UnicodeString&
- UnicodeString::findAndReplace(int32_t start,
- int32_t _length,
- const UnicodeString& oldText,
- const UnicodeString& newText)
- { return findAndReplace(start, _length, oldText, 0, oldText.length(),
- newText, 0, newText.length()); }
- // ============================
- // extract
- // ============================
- inline void
- UnicodeString::doExtract(int32_t start,
- int32_t _length,
- UnicodeString& target) const
- { target.replace(0, target.length(), *this, start, _length); }
- inline void
- UnicodeString::extract(int32_t start,
- int32_t _length,
- UChar *target,
- int32_t targetStart) const
- { doExtract(start, _length, target, targetStart); }
- inline void
- UnicodeString::extract(int32_t start,
- int32_t _length,
- UnicodeString& target) const
- { doExtract(start, _length, target); }
- #if !UCONFIG_NO_CONVERSION
- inline int32_t
- UnicodeString::extract(int32_t start,
- int32_t _length,
- char *dst,
- const char *codepage) const
- {
- // This dstSize value will be checked explicitly
- // Removed #if defined(__GNUC__) per ICU defect http://bugs.icu-project.org/trac/ticket/8197
- return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
- }
- #endif
- inline void
- UnicodeString::extractBetween(int32_t start,
- int32_t limit,
- UChar *dst,
- int32_t dstStart) const {
- pinIndex(start);
- pinIndex(limit);
- doExtract(start, limit - start, dst, dstStart);
- }
- inline UnicodeString
- UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
- return tempSubString(start, limit - start);
- }
- inline UChar
- UnicodeString::doCharAt(int32_t offset) const
- {
- if((uint32_t)offset < (uint32_t)length()) {
- return getArrayStart()[offset];
- } else {
- return kInvalidUChar;
- }
- }
- inline UChar
- UnicodeString::charAt(int32_t offset) const
- { return doCharAt(offset); }
- inline UChar
- UnicodeString::operator[] (int32_t offset) const
- { return doCharAt(offset); }
- inline UChar32
- UnicodeString::char32At(int32_t offset) const
- {
- int32_t len = length();
- if((uint32_t)offset < (uint32_t)len) {
- const UChar *array = getArrayStart();
- UChar32 c;
- U16_GET(array, 0, offset, len, c);
- return c;
- } else {
- return kInvalidUChar;
- }
- }
- inline int32_t
- UnicodeString::getChar32Start(int32_t offset) const {
- if((uint32_t)offset < (uint32_t)length()) {
- const UChar *array = getArrayStart();
- U16_SET_CP_START(array, 0, offset);
- return offset;
- } else {
- return 0;
- }
- }
- inline int32_t
- UnicodeString::getChar32Limit(int32_t offset) const {
- int32_t len = length();
- if((uint32_t)offset < (uint32_t)len) {
- const UChar *array = getArrayStart();
- U16_SET_CP_LIMIT(array, 0, offset, len);
- return offset;
- } else {
- return len;
- }
- }
- inline UBool
- UnicodeString::isEmpty() const {
- return fShortLength == 0;
- }
- //========================================
- // Write implementation methods
- //========================================
- inline void
- UnicodeString::setLength(int32_t len) {
- if(len <= 127) {
- fShortLength = (int8_t)len;
- } else {
- fShortLength = (int8_t)-1;
- fUnion.fFields.fLength = len;
- }
- }
- inline void
- UnicodeString::setToEmpty() {
- fShortLength = 0;
- fFlags = kShortString;
- }
- inline void
- UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
- setLength(len);
- fUnion.fFields.fArray = array;
- fUnion.fFields.fCapacity = capacity;
- }
- inline const UChar *
- UnicodeString::getTerminatedBuffer() {
- if(!isWritable()) {
- return 0;
- } else {
- UChar *array = getArrayStart();
- int32_t len = length();
- if(len < getCapacity() && ((fFlags&kRefCounted) == 0 || refCount() == 1)) {
- /*
- * kRefCounted: Do not write the NUL if the buffer is shared.
- * That is mostly safe, except when the length of one copy was modified
- * without copy-on-write, e.g., via truncate(newLength) or remove(void).
- * Then the NUL would be written into the middle of another copy's string.
- */
- if(!(fFlags&kBufferIsReadonly)) {
- /*
- * We must not write to a readonly buffer, but it is known to be
- * NUL-terminated if len<capacity.
- * A shared, allocated buffer (refCount()>1) must not have its contents
- * modified, but the NUL at [len] is beyond the string contents,
- * and multiple string objects and threads writing the same NUL into the
- * same location is harmless.
- * In all other cases, the buffer is fully writable and it is anyway safe
- * to write the NUL.
- *
- * Note: An earlier version of this code tested whether there is a NUL
- * at [len] already, but, while safe, it generated lots of warnings from
- * tools like valgrind and Purify.
- */
- array[len] = 0;
- }
- return array;
- } else if(cloneArrayIfNeeded(len+1)) {
- array = getArrayStart();
- array[len] = 0;
- return array;
- } else {
- return 0;
- }
- }
- }
- inline UnicodeString&
- UnicodeString::operator= (UChar ch)
- { return doReplace(0, length(), &ch, 0, 1); }
- inline UnicodeString&
- UnicodeString::operator= (UChar32 ch)
- { return replace(0, length(), ch); }
- inline UnicodeString&
- UnicodeString::setTo(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength)
- {
- unBogus();
- return doReplace(0, length(), srcText, srcStart, srcLength);
- }
- inline UnicodeString&
- UnicodeString::setTo(const UnicodeString& srcText,
- int32_t srcStart)
- {
- unBogus();
- srcText.pinIndex(srcStart);
- return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
- }
- inline UnicodeString&
- UnicodeString::setTo(const UnicodeString& srcText)
- {
- unBogus();
- return doReplace(0, length(), srcText, 0, srcText.length());
- }
- inline UnicodeString&
- UnicodeString::setTo(const UChar *srcChars,
- int32_t srcLength)
- {
- unBogus();
- return doReplace(0, length(), srcChars, 0, srcLength);
- }
- inline UnicodeString&
- UnicodeString::setTo(UChar srcChar)
- {
- unBogus();
- return doReplace(0, length(), &srcChar, 0, 1);
- }
- inline UnicodeString&
- UnicodeString::setTo(UChar32 srcChar)
- {
- unBogus();
- return replace(0, length(), srcChar);
- }
- inline UnicodeString&
- UnicodeString::append(const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength)
- { return doReplace(length(), 0, srcText, srcStart, srcLength); }
- inline UnicodeString&
- UnicodeString::append(const UnicodeString& srcText)
- { return doReplace(length(), 0, srcText, 0, srcText.length()); }
- inline UnicodeString&
- UnicodeString::append(const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength)
- { return doReplace(length(), 0, srcChars, srcStart, srcLength); }
- inline UnicodeString&
- UnicodeString::append(const UChar *srcChars,
- int32_t srcLength)
- { return doReplace(length(), 0, srcChars, 0, srcLength); }
- inline UnicodeString&
- UnicodeString::append(UChar srcChar)
- { return doReplace(length(), 0, &srcChar, 0, 1); }
- inline UnicodeString&
- UnicodeString::append(UChar32 srcChar) {
- UChar buffer[U16_MAX_LENGTH];
- int32_t _length = 0;
- UBool isError = FALSE;
- U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError);
- return doReplace(length(), 0, buffer, 0, _length);
- }
- inline UnicodeString&
- UnicodeString::operator+= (UChar ch)
- { return doReplace(length(), 0, &ch, 0, 1); }
- inline UnicodeString&
- UnicodeString::operator+= (UChar32 ch) {
- return append(ch);
- }
- inline UnicodeString&
- UnicodeString::operator+= (const UnicodeString& srcText)
- { return doReplace(length(), 0, srcText, 0, srcText.length()); }
- inline UnicodeString&
- UnicodeString::insert(int32_t start,
- const UnicodeString& srcText,
- int32_t srcStart,
- int32_t srcLength)
- { return doReplace(start, 0, srcText, srcStart, srcLength); }
- inline UnicodeString&
- UnicodeString::insert(int32_t start,
- const UnicodeString& srcText)
- { return doReplace(start, 0, srcText, 0, srcText.length()); }
- inline UnicodeString&
- UnicodeString::insert(int32_t start,
- const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength)
- { return doReplace(start, 0, srcChars, srcStart, srcLength); }
- inline UnicodeString&
- UnicodeString::insert(int32_t start,
- const UChar *srcChars,
- int32_t srcLength)
- { return doReplace(start, 0, srcChars, 0, srcLength); }
- inline UnicodeString&
- UnicodeString::insert(int32_t start,
- UChar srcChar)
- { return doReplace(start, 0, &srcChar, 0, 1); }
- inline UnicodeString&
- UnicodeString::insert(int32_t start,
- UChar32 srcChar)
- { return replace(start, 0, srcChar); }
- inline UnicodeString&
- UnicodeString::remove()
- {
- // remove() of a bogus string makes the string empty and non-bogus
- // we also un-alias a read-only alias to deal with NUL-termination
- // issues with getTerminatedBuffer()
- if(fFlags & (kIsBogus|kBufferIsReadonly)) {
- setToEmpty();
- } else {
- fShortLength = 0;
- }
- return *this;
- }
- inline UnicodeString&
- UnicodeString::remove(int32_t start,
- int32_t _length)
- {
- if(start <= 0 && _length == INT32_MAX) {
- // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
- return remove();
- }
- return doReplace(start, _length, NULL, 0, 0);
- }
- inline UnicodeString&
- UnicodeString::removeBetween(int32_t start,
- int32_t limit)
- { return doReplace(start, limit - start, NULL, 0, 0); }
- inline UnicodeString &
- UnicodeString::retainBetween(int32_t start, int32_t limit) {
- truncate(limit);
- return doReplace(0, start, NULL, 0, 0);
- }
- inline UBool
- UnicodeString::truncate(int32_t targetLength)
- {
- if(isBogus() && targetLength == 0) {
- // truncate(0) of a bogus string makes the string empty and non-bogus
- unBogus();
- return FALSE;
- } else if((uint32_t)targetLength < (uint32_t)length()) {
- setLength(targetLength);
- if(fFlags&kBufferIsReadonly) {
- fUnion.fFields.fCapacity = targetLength; // not NUL-terminated any more
- }
- return TRUE;
- } else {
- return FALSE;
- }
- }
- inline UnicodeString&
- UnicodeString::reverse()
- { return doReverse(0, length()); }
- inline UnicodeString&
- UnicodeString::reverse(int32_t start,
- int32_t _length)
- { return doReverse(start, _length); }
- U_NAMESPACE_END
- #endif
|