PVRTString.cpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  1. /******************************************************************************
  2. @File PVRTString.cpp
  3. @Title PVRTString
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI compatible
  7. @Description A string class that can be used as drop-in replacement for
  8. std::string on platforms/compilers that don't provide a full C++
  9. standard library.
  10. ******************************************************************************/
  11. #include "PVRTString.h"
  12. #ifdef _USING_PVRTSTRING_
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <stdarg.h>
  16. #include "PVRTGlobal.h"
  17. const size_t CPVRTString::npos = (size_t) -1;
  18. #if defined(_WIN32) && !defined(__BADA__)
  19. #define vsnprintf _vsnprintf
  20. #endif
  21. /*!***********************************************************************
  22. @Function CPVRTString
  23. @Input _Ptr A string
  24. @Input _Count Length of _Ptr
  25. @Description Constructor
  26. ************************************************************************/
  27. CPVRTString::CPVRTString(const char* _Ptr, size_t _Count) :
  28. m_pString(0), m_Capacity(0)
  29. {
  30. if (_Count == npos)
  31. assign(_Ptr);
  32. else
  33. assign(_Ptr, _Count);
  34. }
  35. /*!***********************************************************************
  36. @Function CPVRTString
  37. @Input _Right A string
  38. @Input _Roff Offset into _Right
  39. @Input _Count Number of chars from _Right to assign to the new string
  40. @Description Constructor
  41. ************************************************************************/
  42. CPVRTString::CPVRTString(const CPVRTString& _Right, size_t _Roff, size_t _Count) :
  43. m_pString(0), m_Capacity(0)
  44. {
  45. assign(_Right, _Roff, _Count);
  46. }
  47. /*!***********************************************************************
  48. @Function CPVRTString
  49. @Input _Count Length of new string
  50. @Input _Ch A char to fill it with
  51. @Description Constructor
  52. *************************************************************************/
  53. CPVRTString::CPVRTString(size_t _Count, char _Ch) :
  54. m_pString(0), m_Capacity(0)
  55. {
  56. assign(_Count,_Ch);
  57. }
  58. /*!***********************************************************************
  59. @Function CPVRTString
  60. @Input _Ch A char
  61. @Description Constructor
  62. *************************************************************************/
  63. CPVRTString::CPVRTString(const char _Ch) :
  64. m_pString(0), m_Capacity(0)
  65. {
  66. assign( 1, _Ch);
  67. }
  68. /*!***********************************************************************
  69. @Function CPVRTString
  70. @Description Constructor
  71. *************************************************************************/
  72. CPVRTString::CPVRTString() :
  73. m_Size(0), m_Capacity(1)
  74. {
  75. m_pString = (char*)calloc(1, 1);
  76. }
  77. /*!***********************************************************************
  78. @Function ~CPVRTString
  79. @Description Destructor
  80. *************************************************************************/
  81. CPVRTString::~CPVRTString()
  82. {
  83. free(m_pString);
  84. }
  85. /*!***********************************************************************
  86. @Function append
  87. @Input _Ptr A string
  88. @Returns Updated string
  89. @Description Appends a string
  90. *************************************************************************/
  91. CPVRTString& CPVRTString::append(const char* _Ptr)
  92. {
  93. return append(_Ptr,strlen(_Ptr));
  94. }
  95. /*!***********************************************************************
  96. @Function append
  97. @Input _Ptr A string
  98. @Input _Count String length
  99. @Returns Updated string
  100. @Description Appends a string of length _Count
  101. *************************************************************************/
  102. CPVRTString& CPVRTString::append(const char* _Ptr, size_t _Count)
  103. {
  104. char* pString = m_pString;
  105. size_t newCapacity = _Count + m_Size + 1; // +1 for null termination
  106. // extend CPVRTString if necessary
  107. if (m_Capacity < newCapacity)
  108. {
  109. pString = (char*)malloc(newCapacity);
  110. m_Capacity = newCapacity;
  111. memmove(pString, m_pString, m_Size);
  112. pString[m_Capacity-1]='\0';
  113. }
  114. // append chars from _Ptr
  115. memmove(pString + m_Size, _Ptr, _Count);
  116. m_Size += _Count;
  117. pString[m_Size] = 0;
  118. // remove old CPVRTString if necessary
  119. if (pString != m_pString)
  120. {
  121. free(m_pString);
  122. m_pString = pString;
  123. }
  124. return *this;
  125. }
  126. /*!***********************************************************************
  127. @Function append
  128. @Input _Str A string
  129. @Returns Updated string
  130. @Description Appends a string
  131. *************************************************************************/
  132. CPVRTString& CPVRTString::append(const CPVRTString& _Str)
  133. {
  134. return append(_Str.m_pString,_Str.m_Size);
  135. }
  136. /*!***********************************************************************
  137. @Function append
  138. @Input _Str A string
  139. @Input _Off A position in string
  140. @Input _Count Number of letters to append
  141. @Returns Updated string
  142. @Description Appends _Count letters of _Str from _Off in _Str
  143. *************************************************************************/
  144. CPVRTString& CPVRTString::append(const CPVRTString& _Str, size_t _Off, size_t _Count)
  145. {
  146. return append(_Str.m_pString+_Off,_Count);
  147. }
  148. /*!***********************************************************************
  149. @Function append
  150. @Input _Ch A char
  151. @Input _Count Number of times to append _Ch
  152. @Returns Updated string
  153. @Description Appends _Ch _Count times
  154. *************************************************************************/
  155. CPVRTString& CPVRTString::append(size_t _Count, char _Ch)
  156. {
  157. char* pString = m_pString;
  158. size_t newCapacity = _Count + m_Size + 1; // +1 for null termination
  159. // extend CPVRTString if necessary
  160. if (m_Capacity < newCapacity)
  161. {
  162. pString = (char*)malloc(newCapacity);
  163. m_Capacity = newCapacity;
  164. memmove(pString, m_pString, m_Size+1);
  165. }
  166. char* newChar = &pString[m_Size];
  167. // fill new space with _Ch
  168. for(size_t i=0;i<_Count;++i)
  169. {
  170. *newChar++ = _Ch;
  171. }
  172. *newChar = '\0'; // set null terminato
  173. m_Size+=_Count; // adjust length of string for new characters
  174. // remove old CPVRTString if necessary
  175. if (pString != m_pString)
  176. {
  177. free(m_pString);
  178. m_pString = pString;
  179. }
  180. return *this;
  181. }
  182. /*!***********************************************************************
  183. @Function assign
  184. @Input _Ptr A string
  185. @Returns Updated string
  186. @Description Assigns the string to the string _Ptr
  187. *************************************************************************/
  188. CPVRTString& CPVRTString::assign(const char* _Ptr)
  189. {
  190. return assign(_Ptr, strlen(_Ptr));
  191. }
  192. /*!***********************************************************************
  193. @Function assign
  194. @Input _Ptr A string
  195. @Input _Count Length of _Ptr
  196. @Returns Updated string
  197. @Description Assigns the string to the string _Ptr
  198. *************************************************************************/
  199. CPVRTString& CPVRTString::assign(const char* _Ptr, size_t _Count)
  200. {
  201. char* pString = m_pString;
  202. if (m_Capacity <= _Count)
  203. {
  204. pString = (char*)malloc(_Count + 1);
  205. m_Capacity = _Count+1;
  206. }
  207. m_Size = _Count;
  208. memmove(pString, _Ptr, m_Size);
  209. pString[m_Size] = 0;
  210. if (pString != m_pString)
  211. {
  212. free(m_pString);
  213. m_pString = pString;
  214. }
  215. return *this;
  216. }
  217. /*!***********************************************************************
  218. @Function assign
  219. @Input _Str A string
  220. @Returns Updated string
  221. @Description Assigns the string to the string _Str
  222. *************************************************************************/
  223. CPVRTString& CPVRTString::assign(const CPVRTString& _Str)
  224. {
  225. return assign(_Str.m_pString, _Str.m_Size);
  226. }
  227. /*!***********************************************************************
  228. @Function assign
  229. @Input _Str A string
  230. @Input _Off First char to start assignment from
  231. @Input _Count Length of _Str
  232. @Returns Updated string
  233. @Description Assigns the string to _Count characters in string _Str starting at _Off
  234. *************************************************************************/
  235. CPVRTString& CPVRTString::assign(const CPVRTString& _Str, size_t _Off, size_t _Count)
  236. {
  237. if(_Count==npos)
  238. {
  239. _Count = _Str.m_Size - _Off;
  240. }
  241. return assign(&_Str.m_pString[_Off], _Count);
  242. }
  243. /*!***********************************************************************
  244. @Function assign
  245. @Input _Ch A string
  246. @Input _Count Number of times to repeat _Ch
  247. @Returns Updated string
  248. @Description Assigns the string to _Count copies of _Ch
  249. *************************************************************************/
  250. CPVRTString& CPVRTString::assign(size_t _Count,char _Ch)
  251. {
  252. if (m_Capacity <= _Count)
  253. {
  254. free(m_pString);
  255. m_pString = (char*)malloc(_Count + 1);
  256. m_Capacity = _Count+1;
  257. }
  258. m_Size = _Count;
  259. memset(m_pString, _Ch, _Count);
  260. m_pString[m_Size] = 0;
  261. return *this;
  262. }
  263. //const_reference at(size_t _Off) const;
  264. //reference at(size_t _Off);
  265. /*!***********************************************************************
  266. @Function c_str
  267. @Returns const char* pointer of the string
  268. @Description Returns a const char* pointer of the string
  269. *************************************************************************/
  270. const char* CPVRTString::c_str() const
  271. {
  272. return m_pString;
  273. }
  274. /*!***********************************************************************
  275. @Function capacity
  276. @Returns The size of the character array reserved
  277. @Description Returns the size of the character array reserved
  278. *************************************************************************/
  279. size_t CPVRTString::capacity() const
  280. {
  281. return m_Capacity;
  282. }
  283. /*!***********************************************************************
  284. @Function clear
  285. @Description Clears the string
  286. *************************************************************************/
  287. void CPVRTString::clear()
  288. {
  289. free(m_pString);
  290. m_pString = (char*)calloc(1, 1);
  291. m_Size = 0;
  292. m_Capacity = 1;
  293. }
  294. /*!***********************************************************************
  295. @Function compare
  296. @Input _Str A string to compare with
  297. @Returns 0 if the strings match
  298. @Description Compares the string with _Str
  299. *************************************************************************/
  300. int CPVRTString::compare(const CPVRTString& _Str) const
  301. {
  302. return strcmp(m_pString,_Str.m_pString);
  303. }
  304. /*!***********************************************************************
  305. @Function <
  306. @Input _Str A string to compare with
  307. @Returns True on success
  308. @Description Less than operator
  309. *************************************************************************/
  310. bool CPVRTString::operator<(const CPVRTString & _Str) const
  311. {
  312. return (strcmp(m_pString, _Str.m_pString) < 0);
  313. }
  314. /*!***********************************************************************
  315. @Function compare
  316. @Input _Pos1 Position to start comparing from
  317. @Input _Num1 Number of chars to compare
  318. @Input _Str A string to compare with
  319. @Returns 0 if the strings match
  320. @Description Compares the string with _Str
  321. *************************************************************************/
  322. int CPVRTString::compare(size_t _Pos1, size_t _Num1, const CPVRTString& _Str) const
  323. {
  324. _ASSERT(_Pos1<=m_Size); // check comparison starts within lhs CPVRTString
  325. int i32Ret; // value to return if no difference in actual comparisons between chars
  326. size_t stLhsLength = m_Size-_Pos1;
  327. size_t stSearchLength = PVRT_MIN(stLhsLength,PVRT_MIN(_Str.m_Size,_Num1)); // number of comparisons to do
  328. if(PVRT_MIN(stLhsLength,_Num1)<PVRT_MIN(_Str.m_Size,_Num1))
  329. {
  330. i32Ret = -1;
  331. }
  332. else if(PVRT_MIN(stLhsLength,_Num1)>PVRT_MIN(_Str.m_Size,_Num1))
  333. {
  334. i32Ret = 1;
  335. }
  336. else
  337. {
  338. i32Ret = 0;
  339. }
  340. // do actual comparison
  341. const char* lhptr = &m_pString[_Pos1];
  342. const char* rhptr = _Str.m_pString;
  343. for(size_t i=0;i<stSearchLength;++i)
  344. {
  345. if(*lhptr<*rhptr)
  346. return -1;
  347. else if (*lhptr>*rhptr)
  348. return 1;
  349. lhptr++;rhptr++;
  350. }
  351. // no difference found in compared characters
  352. return i32Ret;
  353. }
  354. /*!***********************************************************************
  355. @Function compare
  356. @Input _Pos1 Position to start comparing from
  357. @Input _Num1 Number of chars to compare
  358. @Input _Str A string to compare with
  359. @Input _Off Position in _Str to compare from
  360. @Input _Count Number of chars in _Str to compare with
  361. @Returns 0 if the strings match
  362. @Description Compares the string with _Str
  363. *************************************************************************/
  364. int CPVRTString::compare(size_t _Pos1, size_t _Num1, const CPVRTString& _Str, size_t /*_Off*/, size_t _Count) const
  365. {
  366. _ASSERT(_Pos1<=m_Size); // check comparison starts within lhs CPVRTString
  367. int i32Ret; // value to return if no difference in actual comparisons between chars
  368. size_t stLhsLength = m_Size-_Pos1;
  369. size_t stSearchLength = PVRT_MIN(stLhsLength,PVRT_MIN(_Str.m_Size,PVRT_MIN(_Num1,_Count))); // number of comparisons to do
  370. if(PVRT_MIN(stLhsLength,_Num1)<PVRT_MIN(_Str.m_Size,_Count))
  371. {
  372. i32Ret = -1;
  373. }
  374. else if(PVRT_MIN(stLhsLength,_Num1)>PVRT_MIN(_Str.m_Size,_Count))
  375. {
  376. i32Ret = 1;
  377. }
  378. else
  379. {
  380. i32Ret = 0;
  381. }
  382. // do actual comparison
  383. char* lhptr = &m_pString[_Pos1];
  384. char* rhptr = _Str.m_pString;
  385. for(size_t i=0;i<stSearchLength;++i)
  386. {
  387. if(*lhptr<*rhptr)
  388. return -1;
  389. else if (*lhptr>*rhptr)
  390. return 1;
  391. lhptr++;rhptr++;
  392. }
  393. // no difference found in compared characters
  394. return i32Ret;
  395. }
  396. /*!***********************************************************************
  397. @Function compare
  398. @Input _Ptr A string to compare with
  399. @Returns 0 if the strings match
  400. @Description Compares the string with _Ptr
  401. *************************************************************************/
  402. int CPVRTString::compare(const char* _Ptr) const
  403. {
  404. return strcmp(m_pString,_Ptr);
  405. }
  406. /*!***********************************************************************
  407. @Function compare
  408. @Input _Pos1 Position to start comparing from
  409. @Input _Num1 Number of chars to compare
  410. @Input _Ptr A string to compare with
  411. @Returns 0 if the strings match
  412. @Description Compares the string with _Ptr
  413. *************************************************************************/
  414. int CPVRTString::compare(size_t _Pos1, size_t _Num1, const char* _Ptr) const
  415. {
  416. _ASSERT(_Pos1<=m_Size); // check comparison starts within lhs CPVRTString
  417. int i32Ret; // value to return if no difference in actual comparisons between chars
  418. size_t stLhsLength = m_Size-_Pos1;
  419. size_t stRhsLength = strlen(_Ptr);
  420. size_t stSearchLength = PVRT_MIN(stLhsLength,PVRT_MIN(stRhsLength,_Num1)); // number of comparisons to do
  421. if(PVRT_MIN(stLhsLength,_Num1)<PVRT_MIN(stRhsLength,_Num1))
  422. {
  423. i32Ret = -1;
  424. }
  425. else if(PVRT_MIN(stLhsLength,_Num1)>PVRT_MIN(stRhsLength,_Num1))
  426. {
  427. i32Ret = 1;
  428. }
  429. else
  430. {
  431. i32Ret = 0;
  432. }
  433. // do actual comparison
  434. const char* lhptr = &m_pString[_Pos1];
  435. const char* rhptr = _Ptr;
  436. for(size_t i=0;i<stSearchLength;++i)
  437. {
  438. if(*lhptr<*rhptr)
  439. return -1;
  440. else if (*lhptr>*rhptr)
  441. return 1;
  442. lhptr++;rhptr++;
  443. }
  444. // no difference found in compared characters
  445. return i32Ret;
  446. }
  447. /*!***********************************************************************
  448. @Function compare
  449. @Input _Pos1 Position to start comparing from
  450. @Input _Num1 Number of chars to compare
  451. @Input _Ptr A string to compare with
  452. @Input _Count Number of char to compare
  453. @Returns 0 if the strings match
  454. @Description Compares the string with _Str
  455. *************************************************************************/
  456. int CPVRTString::compare(size_t _Pos1, size_t _Num1, const char* _Ptr, size_t _Count) const
  457. {
  458. _ASSERT(_Pos1<=m_Size); // check comparison starts within lhs CPVRTString
  459. int i32Ret; // value to return if no difference in actual comparisons between chars
  460. size_t stLhsLength = m_Size-_Pos1;
  461. size_t stRhsLength = strlen(_Ptr);
  462. size_t stSearchLength = PVRT_MIN(stLhsLength,PVRT_MIN(stRhsLength,PVRT_MIN(_Num1,_Count))); // number of comparisons to do
  463. if(PVRT_MIN(stLhsLength,_Num1)<PVRT_MIN(stRhsLength,_Count))
  464. {
  465. i32Ret = -1;
  466. }
  467. else if(PVRT_MIN(stLhsLength,_Num1)>PVRT_MIN(stRhsLength,_Count))
  468. {
  469. i32Ret = 1;
  470. }
  471. else
  472. {
  473. i32Ret = 0;
  474. }
  475. // do actual comparison
  476. char* lhptr = &m_pString[_Pos1];
  477. const char* rhptr = _Ptr;
  478. for(size_t i=0;i<stSearchLength;++i)
  479. {
  480. if(*lhptr<*rhptr)
  481. return -1;
  482. else if (*lhptr>*rhptr)
  483. return 1;
  484. lhptr++;rhptr++;
  485. }
  486. // no difference found in compared characters
  487. return i32Ret;
  488. }
  489. /*!***********************************************************************
  490. @Function ==
  491. @Input _Str A string to compare with
  492. @Returns True if they match
  493. @Description == Operator
  494. *************************************************************************/
  495. bool CPVRTString::operator==(const CPVRTString& _Str) const
  496. {
  497. return strcmp(m_pString, _Str.m_pString)==0;
  498. }
  499. /*!***********************************************************************
  500. @Function ==
  501. @Input _Ptr A string to compare with
  502. @Returns True if they match
  503. @Description == Operator
  504. *************************************************************************/
  505. bool CPVRTString::operator==(const char* const _Ptr) const
  506. {
  507. return strcmp(m_pString, _Ptr)==0;
  508. }
  509. /*!***********************************************************************
  510. @Function !=
  511. @Input _Str A string to compare with
  512. @Returns True if they don't match
  513. @Description != Operator
  514. *************************************************************************/
  515. bool CPVRTString::operator!=(const CPVRTString& _Str) const
  516. {
  517. return strcmp(m_pString, _Str.m_pString)!=0;
  518. }
  519. /*!***********************************************************************
  520. @Function !=
  521. @Input _Ptr A string to compare with
  522. @Returns True if they don't match
  523. @Description != Operator
  524. *************************************************************************/
  525. bool CPVRTString::operator!=(const char* const _Ptr) const
  526. {
  527. return strcmp(m_pString, _Ptr)!=0;
  528. }
  529. /*!***********************************************************************
  530. @Function copy
  531. @Modified _Ptr A string to copy to
  532. @Input _Count Size of _Ptr
  533. @Input _Off Position to start copying from
  534. @Returns Number of bytes copied
  535. @Description Copies the string to _Ptr
  536. *************************************************************************/
  537. size_t CPVRTString::copy(char* _Ptr, size_t _Count, size_t _Off) const
  538. {
  539. if(memcpy(_Ptr, &m_pString[_Off], PVRT_MIN(_Count, m_Size - _Off)))
  540. return _Count;
  541. return 0;
  542. }
  543. /*!***********************************************************************
  544. @Function data
  545. @Returns A const char* version of the string
  546. @Description Returns a const char* version of the string
  547. *************************************************************************/
  548. const char* CPVRTString::data() const
  549. {
  550. return m_pString;
  551. }
  552. /*!***********************************************************************
  553. @Function empty
  554. @Returns True if the string is empty
  555. @Description Returns true if the string is empty
  556. *************************************************************************/
  557. bool CPVRTString::empty() const
  558. {
  559. return (m_Size == 0);
  560. }
  561. /*!***********************************************************************
  562. @Function erase
  563. @Input _Pos The position to start erasing from
  564. @Input _Count Number of chars to erase
  565. @Returns An updated string
  566. @Description Erases a portion of the string
  567. *************************************************************************/
  568. CPVRTString& CPVRTString::erase(size_t _Pos, size_t _Count)
  569. {
  570. if (_Count == npos || _Pos + _Count >= m_Size)
  571. {
  572. resize(_Pos, 0);
  573. }
  574. else
  575. {
  576. memmove(&m_pString[_Pos], &m_pString[_Pos + _Count], m_Size + 1 - (_Pos + _Count));
  577. }
  578. return *this;
  579. }
  580. /*!***********************************************************************
  581. @Function find_first_not_of
  582. @Input _Ch A char
  583. @Input _Off Start position of the find
  584. @Returns Position of the first char that is not _Ch
  585. @Description Returns the position of the first char that is not _Ch
  586. *************************************************************************/
  587. size_t CPVRTString::find_first_not_of(char _Ch, size_t _Off) const
  588. {
  589. for(size_t i=_Off;i<m_Size;++i)
  590. {
  591. if(m_pString[i]!=_Ch)
  592. return i;
  593. }
  594. return npos;
  595. }
  596. /*!***********************************************************************
  597. @Function find_first_not_of
  598. @Input _Ptr A string
  599. @Input _Off Start position of the find
  600. @Returns Position of the first char that is not in _Ptr
  601. @Description Returns the position of the first char that is not in _Ptr
  602. *************************************************************************/
  603. size_t CPVRTString::find_first_not_of(const char* _Ptr, size_t _Off) const
  604. {
  605. for(size_t i=_Off;i<m_Size;++i)
  606. {
  607. bool bFound = false;
  608. // compare against each char from _Ptr
  609. for(size_t j=0;_Ptr[j]!=0;++j)
  610. {
  611. bFound = bFound || (m_pString[i]==_Ptr[j]);
  612. }
  613. if(!bFound)
  614. { // return if no match
  615. return i;
  616. }
  617. }
  618. return npos;
  619. }
  620. /*!***********************************************************************
  621. @Function find_first_not_of
  622. @Input _Ptr A string
  623. @Input _Off Start position of the find
  624. @Input _Count Number of chars in _Ptr
  625. @Returns Position of the first char that is not in _Ptr
  626. @Description Returns the position of the first char that is not in _Ptr
  627. *************************************************************************/
  628. size_t CPVRTString::find_first_not_of(const char* _Ptr, size_t _Off, size_t _Count) const
  629. {
  630. for(size_t i=_Off;i<m_Size;++i)
  631. {
  632. bool bFound = false;
  633. // compare against each char from _Ptr
  634. for(size_t j=0;j<_Count;++j)
  635. {
  636. bFound = bFound || (m_pString[i]==_Ptr[j]);
  637. }
  638. if(!bFound)
  639. { // return if no match
  640. return i;
  641. }
  642. }
  643. return npos;
  644. }
  645. /*!***********************************************************************
  646. @Function find_first_not_of
  647. @Input _Str A string
  648. @Input _Off Start position of the find
  649. @Returns Position of the first char that is not in _Str
  650. @Description Returns the position of the first char that is not in _Str
  651. *************************************************************************/
  652. size_t CPVRTString::find_first_not_of(const CPVRTString& _Str, size_t _Off) const
  653. {
  654. for(size_t i=_Off;i<m_Size;++i)
  655. {
  656. bool bFound = false;
  657. // compare against each char from _Str
  658. for(size_t j=0;j<_Str.m_Size;++j)
  659. {
  660. bFound = bFound || (m_pString[i]==_Str[j]);
  661. }
  662. if(!bFound)
  663. { // return if no match
  664. return i;
  665. }
  666. }
  667. return npos;
  668. }
  669. /*!***********************************************************************
  670. @Function find_first_of
  671. @Input _Ch A char
  672. @Input _Off Start position of the find
  673. @Returns Position of the first char that is _Ch
  674. @Description Returns the position of the first char that is _Ch
  675. *************************************************************************/
  676. size_t CPVRTString::find_first_of(char _Ch, size_t _Off) const
  677. {
  678. for(size_t i=_Off;i<m_Size;++i)
  679. {
  680. if(m_pString[i]==_Ch)
  681. return i;
  682. }
  683. return npos;
  684. }
  685. /*!***********************************************************************
  686. @Function find_first_of
  687. @Input _Ptr A string
  688. @Input _Off Start position of the find
  689. @Returns Position of the first char that matches a char in _Ptr
  690. @Description Returns the position of the first char that matches a char in _Ptr
  691. *************************************************************************/
  692. size_t CPVRTString::find_first_of(const char* _Ptr, size_t _Off) const
  693. {
  694. for(size_t i=_Off;i<m_Size;++i)
  695. {
  696. // compare against each char from _Ptr
  697. for(size_t j=0;_Ptr[j]!=0;++j)
  698. {
  699. if(m_pString[i]==_Ptr[j])
  700. return i;
  701. }
  702. }
  703. return npos;
  704. }
  705. /*!***********************************************************************
  706. @Function find_first_of
  707. @Input _Ptr A string
  708. @Input _Off Start position of the find
  709. @Input _Count Size of _Ptr
  710. @Returns Position of the first char that matches a char in _Ptr
  711. @Description Returns the position of the first char that matches a char in _Ptr
  712. *************************************************************************/
  713. size_t CPVRTString::find_first_of(const char* _Ptr, size_t _Off, size_t _Count) const
  714. {
  715. for(size_t i=_Off;i<m_Size;++i)
  716. {
  717. // compare against each char from _Ptr
  718. for(size_t j=0;j<_Count;++j)
  719. {
  720. if(m_pString[i]==_Ptr[j])
  721. return i;
  722. }
  723. }
  724. return npos;
  725. }
  726. /*!***********************************************************************
  727. @Function find_first_of
  728. @Input _Str A string
  729. @Input _Off Start position of the find
  730. @Returns Position of the first char that matches a char in _Str
  731. @Description Returns the position of the first char that matches a char in _Str
  732. *************************************************************************/
  733. size_t CPVRTString::find_first_of(const CPVRTString& _Str, size_t _Off) const
  734. {
  735. for(size_t i=_Off;i<m_Size;++i)
  736. {
  737. // compare against each char from _Ptr
  738. for(size_t j=0;j<_Str.m_Size;++j)
  739. {
  740. if(m_pString[i]==_Str[j])
  741. return i;
  742. }
  743. }
  744. return npos;
  745. }
  746. /*!***********************************************************************
  747. @Function find_last_not_of
  748. @Input _Ch A char
  749. @Input _Off Start position of the find
  750. @Returns Position of the last char that is not _Ch
  751. @Description Returns the position of the last char that is not _Ch
  752. *************************************************************************/
  753. size_t CPVRTString::find_last_not_of(char _Ch, size_t _Off) const
  754. {
  755. for(size_t i=m_Size-_Off-1;i<m_Size;--i)
  756. {
  757. if(m_pString[i]!=_Ch)
  758. {
  759. return i;
  760. }
  761. }
  762. return npos;
  763. }
  764. /*!***********************************************************************
  765. @Function find_last_not_of
  766. @Input _Ptr A string
  767. @Input _Off Start position of the find
  768. @Returns Position of the last char that is not in _Ptr
  769. @Description Returns the position of the last char that is not in _Ptr
  770. *************************************************************************/
  771. size_t CPVRTString::find_last_not_of(const char* _Ptr, size_t _Off) const
  772. {
  773. for(size_t i=m_Size-_Off-1;i<m_Size;--i)
  774. {
  775. bool bFound = true;
  776. // compare against each char from _Ptr
  777. for(size_t j=0;_Ptr[j]!=0;++j)
  778. {
  779. bFound = bFound && (m_pString[i]!=_Ptr[j]);
  780. }
  781. if(bFound)
  782. { // return if considered character differed from all characters from _Ptr
  783. return i;
  784. }
  785. }
  786. return npos;
  787. }
  788. /*!***********************************************************************
  789. @Function find_last_not_of
  790. @Input _Ptr A string
  791. @Input _Off Start position of the find
  792. @Input _Count Length of _Ptr
  793. @Returns Position of the last char that is not in _Ptr
  794. @Description Returns the position of the last char that is not in _Ptr
  795. *************************************************************************/
  796. size_t CPVRTString::find_last_not_of(const char* _Ptr, size_t _Off, size_t _Count) const
  797. {
  798. for(size_t i=m_Size-_Off-1;i<m_Size;--i)
  799. {
  800. bool bFound = true;
  801. // compare against each char from _Ptr
  802. for(size_t j=0;j<_Count;++j)
  803. {
  804. bFound = bFound && (m_pString[i]!=_Ptr[j]);
  805. }
  806. if(bFound)
  807. {
  808. // return if considered character differed from all characters from _Ptr
  809. return i;
  810. }
  811. }
  812. return npos;
  813. }
  814. /*!***********************************************************************
  815. @Function find_last_not_of
  816. @Input _Str A string
  817. @Input _Off Start position of the find
  818. @Returns Position of the last char that is not in _Str
  819. @Description Returns the position of the last char that is not in _Str
  820. *************************************************************************/
  821. size_t CPVRTString::find_last_not_of(const CPVRTString& _Str, size_t _Off) const
  822. {
  823. for(size_t i=m_Size-_Off-1;i<m_Size;--i)
  824. {
  825. bool bFound = true;
  826. // compare against each char from _Ptr
  827. for(size_t j=0;j<_Str.m_Size;++j)
  828. {
  829. bFound = bFound && (m_pString[i]!=_Str[j]);
  830. }
  831. if(bFound)
  832. {
  833. // return if considered character differed from all characters from _Ptr
  834. return i;
  835. }
  836. }
  837. return npos;
  838. }
  839. /*!***********************************************************************
  840. @Function find_last_of
  841. @Input _Ch A char
  842. @Input _Off Start position of the find
  843. @Returns Position of the last char that is _Ch
  844. @Description Returns the position of the last char that is _Ch
  845. *************************************************************************/
  846. size_t CPVRTString::find_last_of(char _Ch, size_t _Off) const
  847. {
  848. for(size_t i=m_Size-_Off-1;i<m_Size;--i)
  849. {
  850. if(m_pString[i]==_Ch)
  851. {
  852. return i;
  853. }
  854. }
  855. return npos;
  856. }
  857. /*!***********************************************************************
  858. @Function find_last_of
  859. @Input _Ptr A string
  860. @Input _Off Start position of the find
  861. @Returns Position of the last char that is in _Ptr
  862. @Description Returns the position of the last char that is in _Ptr
  863. *************************************************************************/
  864. size_t CPVRTString::find_last_of(const char* _Ptr, size_t _Off) const
  865. {
  866. for(size_t i=m_Size-_Off-1;i<m_Size;--i)
  867. {
  868. // compare against each char from _Ptr
  869. for(size_t j=0;_Ptr[j]!=0;++j)
  870. {
  871. if(m_pString[i]==_Ptr[j])
  872. return i;
  873. }
  874. }
  875. return npos;
  876. }
  877. /*!***********************************************************************
  878. @Function find_last_of
  879. @Input _Ptr A string
  880. @Input _Off Start position of the find
  881. @Input _Count Length of _Ptr
  882. @Returns Position of the last char that is in _Ptr
  883. @Description Returns the position of the last char that is in _Ptr
  884. *************************************************************************/
  885. size_t CPVRTString::find_last_of(const char* _Ptr, size_t _Off, size_t _Count) const
  886. {
  887. for(size_t i=m_Size-_Off-1;i<m_Size;--i)
  888. {
  889. // compare against each char from _Ptr
  890. for(size_t j=0;j<_Count;++j)
  891. {
  892. if(m_pString[i]!=_Ptr[j])
  893. return i;
  894. }
  895. }
  896. return npos;
  897. }
  898. /*!***********************************************************************
  899. @Function find_last_of
  900. @Input _Str A string
  901. @Input _Off Start position of the find
  902. @Returns Position of the last char that is in _Str
  903. @Description Returns the position of the last char that is in _Str
  904. *************************************************************************/
  905. size_t CPVRTString::find_last_of(const CPVRTString& _Str, size_t _Off) const
  906. {
  907. for(size_t i=m_Size-_Off-1;i<m_Size;--i)
  908. {
  909. // compare against each char from _Str
  910. for(size_t j=0;j<_Str.m_Size;++j)
  911. {
  912. if(m_pString[i]!=_Str[j])
  913. return i;
  914. }
  915. }
  916. return npos;
  917. }
  918. //CPVRTString& CPVRTString::insert(size_t _P0, const char* _Ptr)
  919. //{
  920. // return replace(_P0, 0, _Ptr);
  921. //}
  922. //CPVRTString& CPVRTString::insert(size_t _P0, const char* _Ptr, size_t _Count)
  923. //{
  924. // return replace(_P0, 0, _Ptr, _Count);
  925. //}
  926. //CPVRTString& CPVRTString::insert(size_t _P0, const CPVRTString& _Str)
  927. //{
  928. // return replace(_P0, 0, _Str);
  929. //}
  930. //CPVRTString& CPVRTString::insert(size_t _P0, const CPVRTString& _Str, size_t _Off, size_t _Count)
  931. //{
  932. // return replace(_P0, 0, _Str, _Off, _Count);
  933. //}
  934. //CPVRTString& CPVRTString::insert(size_t _P0, size_t _Count, char _Ch)
  935. //{
  936. // return replace(_P0, 0, _Count, _Ch);
  937. //}
  938. /*!***********************************************************************
  939. @Function length
  940. @Returns Length of the string
  941. @Description Returns the length of the string
  942. *************************************************************************/
  943. size_t CPVRTString::length() const
  944. {
  945. return m_Size;
  946. }
  947. /*!***********************************************************************
  948. @Function max_size
  949. @Returns The maximum number of chars that the string can contain
  950. @Description Returns the maximum number of chars that the string can contain
  951. *************************************************************************/
  952. size_t CPVRTString::max_size() const
  953. {
  954. return 0x7FFFFFFF;
  955. }
  956. /*!***********************************************************************
  957. @Function push_back
  958. @Input _Ch A char to append
  959. @Description Appends _Ch to the string
  960. *************************************************************************/
  961. void CPVRTString::push_back(char _Ch)
  962. {
  963. append(_Ch, 1);
  964. }
  965. //CPVRTString& replace(size_t _Pos1, size_t _Num1, const char* _Ptr)
  966. //CPVRTString& replace(size_t _Pos1, size_t _Num1, const CPVRTString& _Str)
  967. //CPVRTString& replace(size_t _Pos1, size_t _Num1, const char* _Ptr, size_t _Num2)
  968. //CPVRTString& replace(size_t _Pos1, size_t _Num1, const CPVRTString& _Str, size_t _Pos2, size_t _Num2)
  969. //CPVRTString& replace(size_t _Pos1, size_t _Num1, size_t _Count, char _Ch)
  970. /*!***********************************************************************
  971. @Function reserve
  972. @Input _Count Size of string to reserve
  973. @Description Reserves space for _Count number of chars
  974. *************************************************************************/
  975. void CPVRTString::reserve(size_t _Count)
  976. {
  977. if (_Count >= m_Capacity)
  978. {
  979. m_pString = (char*)realloc(m_pString, _Count + 1);
  980. m_Capacity = _Count + 1;
  981. }
  982. }
  983. /*!***********************************************************************
  984. @Function resize
  985. @Input _Count Size of string to resize to
  986. @Input _Ch Character to use to fill any additional space
  987. @Description Resizes the string to _Count in length
  988. *************************************************************************/
  989. void CPVRTString::resize(size_t _Count, char _Ch)
  990. {
  991. if (_Count <= m_Size)
  992. {
  993. m_Size = _Count;
  994. m_pString[m_Size] = 0;
  995. }
  996. else
  997. {
  998. append(_Count - m_Size,_Ch);
  999. }
  1000. }
  1001. //size_t rfind(char _Ch, size_t _Off = npos) const;
  1002. //size_t rfind(const char* _Ptr, size_t _Off = npos) const;
  1003. //size_t rfind(const char* _Ptr, size_t _Off = npos, size_t _Count) const;
  1004. //size_t rfind(const CPVRTString& _Str, size_t _Off = npos) const;
  1005. /*!***********************************************************************
  1006. @Function size
  1007. @Returns Size of the string
  1008. @Description Returns the size of the string
  1009. *************************************************************************/
  1010. size_t CPVRTString::size() const
  1011. {
  1012. return m_Size;
  1013. }
  1014. /*!***********************************************************************
  1015. @Function substr
  1016. @Input _Off Start of the substring
  1017. @Input _Count Length of the substring
  1018. @Returns A substring of the string
  1019. @Description Returns the size of the string
  1020. *************************************************************************/
  1021. CPVRTString CPVRTString::substr(size_t _Off, size_t _Count) const
  1022. {
  1023. return CPVRTString(*this, _Off, _Count);
  1024. }
  1025. /*!***********************************************************************
  1026. @Function swap
  1027. @Input _Str A string to swap with
  1028. @Description Swaps the contents of the string with _Str
  1029. *************************************************************************/
  1030. void CPVRTString::swap(CPVRTString& _Str)
  1031. {
  1032. size_t Size = _Str.m_Size;
  1033. size_t Capacity = _Str.m_Capacity;
  1034. char* pString = _Str.m_pString;
  1035. _Str.m_Size = m_Size;
  1036. _Str.m_Capacity = m_Capacity;
  1037. _Str.m_pString = m_pString;
  1038. m_Size = Size;
  1039. m_Capacity = Capacity;
  1040. m_pString = pString;
  1041. }
  1042. /*!***********************************************************************
  1043. @Function toLower
  1044. @Returns An updated string
  1045. @Description Converts the string to lower case
  1046. *************************************************************************/
  1047. CPVRTString& CPVRTString::toLower()
  1048. {
  1049. int i = 0;
  1050. while ( (m_pString[i] = (m_pString[i]>='A'&&m_pString[i]<='Z') ? ('a'+m_pString[i])-'A': m_pString[i]) != 0) i++;
  1051. return *this;
  1052. }
  1053. /*!***********************************************************************
  1054. @Function +=
  1055. @Input _Ch A char
  1056. @Returns An updated string
  1057. @Description += Operator
  1058. *************************************************************************/
  1059. CPVRTString& CPVRTString::operator+=(char _Ch)
  1060. {
  1061. return append(_Ch, 1);
  1062. }
  1063. /*!***********************************************************************
  1064. @Function +=
  1065. @Input _Ptr A string
  1066. @Returns An updated string
  1067. @Description += Operator
  1068. *************************************************************************/
  1069. CPVRTString& CPVRTString::operator+=(const char* _Ptr)
  1070. {
  1071. return append(_Ptr);
  1072. }
  1073. /*!***********************************************************************
  1074. @Function +=
  1075. @Input _Right A string
  1076. @Returns An updated string
  1077. @Description += Operator
  1078. *************************************************************************/
  1079. CPVRTString& CPVRTString::operator+=(const CPVRTString& _Right)
  1080. {
  1081. return append(_Right);
  1082. }
  1083. /*!***********************************************************************
  1084. @Function =
  1085. @Input _Ch A char
  1086. @Returns An updated string
  1087. @Description = Operator
  1088. *************************************************************************/
  1089. CPVRTString& CPVRTString::operator=(char _Ch)
  1090. {
  1091. return assign(_Ch, 1);
  1092. }
  1093. /*!***********************************************************************
  1094. @Function =
  1095. @Input _Ptr A string
  1096. @Returns An updated string
  1097. @Description = Operator
  1098. *************************************************************************/
  1099. CPVRTString& CPVRTString::operator=(const char* _Ptr)
  1100. {
  1101. return assign(_Ptr);
  1102. }
  1103. /*!***********************************************************************
  1104. @Function =
  1105. @Input _Right A string
  1106. @Returns An updated string
  1107. @Description = Operator
  1108. *************************************************************************/
  1109. CPVRTString& CPVRTString::operator=(const CPVRTString& _Right)
  1110. {
  1111. return assign(_Right);
  1112. }
  1113. /*!***********************************************************************
  1114. @Function []
  1115. @Input _Off An index into the string
  1116. @Returns A character
  1117. @Description [] Operator
  1118. *************************************************************************/
  1119. CPVRTString::const_reference CPVRTString::operator[](size_t _Off) const
  1120. {
  1121. return m_pString[_Off];
  1122. }
  1123. /*!***********************************************************************
  1124. @Function []
  1125. @Input _Off An index into the string
  1126. @Returns A character
  1127. @Description [] Operator
  1128. *************************************************************************/
  1129. CPVRTString::reference CPVRTString::operator[](size_t _Off)
  1130. {
  1131. return m_pString[_Off];
  1132. }
  1133. /*!***********************************************************************
  1134. @Function +
  1135. @Input _Left A string
  1136. @Input _Right A string
  1137. @Returns An updated string
  1138. @Description + Operator
  1139. *************************************************************************/
  1140. CPVRTString operator+ (const CPVRTString& _Left, const CPVRTString& _Right)
  1141. {
  1142. return CPVRTString(_Left).append(_Right);
  1143. }
  1144. /*!***********************************************************************
  1145. @Function +
  1146. @Input _Left A string
  1147. @Input _Right A string
  1148. @Returns An updated string
  1149. @Description + Operator
  1150. *************************************************************************/
  1151. CPVRTString operator+ (const CPVRTString& _Left, const char* _Right)
  1152. {
  1153. return CPVRTString(_Left).append(_Right);
  1154. }
  1155. /*!***********************************************************************
  1156. @Function +
  1157. @Input _Left A string
  1158. @Input _Right A string
  1159. @Returns An updated string
  1160. @Description + Operator
  1161. *************************************************************************/
  1162. CPVRTString operator+ (const CPVRTString& _Left, const char _Right)
  1163. {
  1164. return CPVRTString(_Left).append(_Right);
  1165. }
  1166. /*!***********************************************************************
  1167. @Function +
  1168. @Input _Left A string
  1169. @Input _Right A string
  1170. @Returns An updated string
  1171. @Description + Operator
  1172. *************************************************************************/
  1173. CPVRTString operator+ (const char* _Left, const CPVRTString& _Right)
  1174. {
  1175. return CPVRTString(_Left).append(_Right);
  1176. }
  1177. /*!***********************************************************************
  1178. @Function +
  1179. @Input _Left A string
  1180. @Input _Right A string
  1181. @Returns An updated string
  1182. @Description + Operator
  1183. *************************************************************************/
  1184. CPVRTString operator+ (const char _Left, const CPVRTString& _Right)
  1185. {
  1186. return CPVRTString(_Left).append(_Right);
  1187. }
  1188. /*************************************************************************
  1189. * MISCELLANEOUS UTILITY FUNCTIONS
  1190. *************************************************************************/
  1191. /*!***********************************************************************
  1192. @Function PVRTStringGetFileExtension
  1193. @Input strFilePath A string
  1194. @Returns Extension
  1195. @Description Extracts the file extension from a file path.
  1196. Returns an empty CPVRTString if no extension is found.
  1197. ************************************************************************/
  1198. CPVRTString PVRTStringGetFileExtension(const CPVRTString& strFilePath)
  1199. {
  1200. CPVRTString::size_type idx = strFilePath.find_last_of ( '.' );
  1201. if (idx == CPVRTString::npos)
  1202. return CPVRTString("");
  1203. else
  1204. return strFilePath.substr(idx);
  1205. }
  1206. /*!***********************************************************************
  1207. @Function PVRTStringGetContainingDirectoryPath
  1208. @Input strFilePath A string
  1209. @Returns Directory
  1210. @Description Extracts the directory portion from a file path.
  1211. ************************************************************************/
  1212. CPVRTString PVRTStringGetContainingDirectoryPath(const CPVRTString& strFilePath)
  1213. {
  1214. size_t i32sep = strFilePath.find_last_of('/');
  1215. if(i32sep == strFilePath.npos)
  1216. {
  1217. i32sep = strFilePath.find_last_of('\\');
  1218. if(i32sep == strFilePath.npos)
  1219. { // can't find an actual \ or /, so return an empty string
  1220. return CPVRTString("");
  1221. }
  1222. }
  1223. return strFilePath.substr(0,i32sep);
  1224. }
  1225. /*!***********************************************************************
  1226. @Function PVRTStringGetFileName
  1227. @Input strFilePath A string
  1228. @Returns FileName
  1229. @Description Extracts the name and extension portion from a file path.
  1230. ************************************************************************/
  1231. CPVRTString PVRTStringGetFileName(const CPVRTString& strFilePath)
  1232. {
  1233. size_t i32sep = strFilePath.find_last_of('/');
  1234. if(i32sep == strFilePath.npos)
  1235. {
  1236. i32sep = strFilePath.find_last_of('\\');
  1237. if(i32sep == strFilePath.npos)
  1238. { // can't find an actual \ or / so leave it be
  1239. return strFilePath;
  1240. }
  1241. }
  1242. return strFilePath.substr(i32sep+1,strFilePath.length());
  1243. }
  1244. /*!***********************************************************************
  1245. @Function PVRTStringStripWhiteSpaceFromStartOf
  1246. @Input strLine A string
  1247. @Returns Result of the white space stripping
  1248. @Description strips white space characters from the beginning of a CPVRTString.
  1249. ************************************************************************/
  1250. CPVRTString PVRTStringStripWhiteSpaceFromStartOf(const CPVRTString& strLine)
  1251. {
  1252. size_t start = strLine.find_first_not_of(" \t \n\r");
  1253. if(start!=strLine.npos)
  1254. return strLine.substr(start,strLine.length()-(start));
  1255. return strLine;
  1256. }
  1257. /*!***********************************************************************
  1258. @Function PVRTStringStripWhiteSpaceFromEndOf
  1259. @Input strLine A string
  1260. @Returns Result of the white space stripping
  1261. @Description strips white space characters from the end of a CPVRTString.
  1262. ************************************************************************/
  1263. CPVRTString PVRTStringStripWhiteSpaceFromEndOf(const CPVRTString& strLine)
  1264. {
  1265. size_t end = strLine.find_last_not_of(" \t \n\r");
  1266. if(end!=strLine.npos)
  1267. return strLine.substr(0,end+1);
  1268. return strLine;
  1269. }
  1270. /*!***********************************************************************
  1271. @Function PVRTStringFromFormattedStr
  1272. @Input pFormat A string containing the formating
  1273. @Returns A formatted string
  1274. @Description Creates a formatted string
  1275. ************************************************************************/
  1276. CPVRTString PVRTStringFromFormattedStr(const char *pFormat, ...)
  1277. {
  1278. va_list arg;
  1279. char buf[1024];
  1280. va_start(arg, pFormat);
  1281. #if defined(__SYMBIAN32__) || defined(UITRON) || defined(_UITRON_)
  1282. vsprintf(buf, pFormat, arg);
  1283. #else
  1284. vsnprintf(buf, 1024, pFormat, arg);
  1285. #endif
  1286. va_end(arg);
  1287. return buf;
  1288. }
  1289. ///*!***************************************************************************
  1290. #endif // _USING_PVRTSTRING_
  1291. /*****************************************************************************
  1292. End of file (PVRTString.cpp)
  1293. *****************************************************************************/