3232
3333#ifdef __cplusplus
3434
35- #define __version__ " 1 .0.0 "
35+ #define __version__ " 2 .0.1 "
3636#define __author__ " Usama Azad"
3737
3838#include " usastringfunctool.h"
@@ -70,9 +70,9 @@ namespace usa
7070
7171 __STDSTRING__ Lower_Case (__STDSTRING__ str);
7272
73- __MYSTRING_REF__ replace_ch (__CHAR__ _old, __CHAR__ _new, __BOOL__ first = false );
73+ __MYSTRING_REF__ replace_ch (const __CHAR__ & _old, const __CHAR__ & _new, __BOOL__ first = false );
7474
75- __MYSTRING_REF__ replace_str (__STDSTRING__ _old, __STDSTRING__ _new, __BOOL__ first = false );
75+ __MYSTRING_REF__ replace_str (const __STDSTRING__ & _old, const __STDSTRING__ & _new, __BOOL__ first = false );
7676
7777 public:
7878
@@ -81,31 +81,31 @@ namespace usa
8181 * different data types.
8282 ************************************************************************/
8383
84- string () : std::string() {}
84+ string () : std::string() {}
8585
86- string (const char *str) : std::string(str) {}
86+ string (const char *str) : std::string(str) {}
8787
88- string (const __STDSTRING__ str) : std::string(str) {}
88+ string (const __STDSTRING__ & str) : std::string(str) {}
8989
90- string (const __BOOL__ val) : std::string(BtoS(val)) {}
90+ string (const __BOOL__ & val) : std::string(BtoS(val)) {}
9191
92- string (const __CHAR__ val) : std::string(CtoS(val)) {}
92+ string (const __CHAR__ & val) : std::string(CtoS(val)) {}
9393
94- string (const __DOUBLE__ val) : std::string(DtoS(val)) {}
94+ string (const __DOUBLE__ & val) : std::string(DtoS(val)) {}
9595
96- string (const __FLOAT__ val) : std::string(FtoS(val)) {}
96+ string (const __FLOAT__ & val) : std::string(FtoS(val)) {}
9797
98- string (const __LDOUBLE__ val) : std::string(LDtoS(val)) {}
98+ string (const __LDOUBLE__ & val) : std::string(LDtoS(val)) {}
9999
100- string (const __INT__ val) : std::string(to_string(val)) {}
100+ string (const __INT__ & val) : std::string(to_string(val)) {}
101101
102- string (const __LONG__ val) : std::string(to_string(val)) {}
102+ string (const __LONG__ & val) : std::string(to_string(val)) {}
103103
104104 template <typename type>
105- string (const std::initializer_list<type> val)
105+ string (const std::initializer_list<type> & val)
106106 {
107107 __STDSTRING__ res = " " ;
108- for (auto i : val)
108+ for (const auto & i : val)
109109 res += string (i);
110110 this ->assign (res);
111111 }
@@ -171,7 +171,33 @@ namespace usa
171171
172172 /* ***********************************************************************/
173173
174-
174+
175+
176+ /* **********************************************************************
177+ * @c Some others operators.
178+ ************************************************************************/
179+
180+ __MYSTRING_REF__ operator *(int times)
181+ {
182+ times = (times < 0 ) ? abs (times) : (times == 0 ) ? 1 : times;
183+ const std::string s = *this ;
184+ for (; --times;)
185+ this ->append (s);
186+ return *this ;
187+ }
188+
189+ template <typename T>
190+ __MYSTRING_REF__ operator <<(const T& obj) {
191+ return this ->join (string (obj));
192+ }
193+
194+ __MYSTRING_REF__ operator ~() {
195+ return this ->reverse ();
196+ }
197+
198+ /* ***********************************************************************/
199+
200+
175201
176202 /* **********************************************************************
177203 * @name is_space
@@ -180,7 +206,7 @@ namespace usa
180206 * @return bool : Return true if the string is a whitespace string,
181207 * else false.
182208 ************************************************************************/
183- __BOOL__ is_space ();
209+ __BOOL__ is_space () const ;
184210 /* ***********************************************************************/
185211
186212
@@ -191,7 +217,7 @@ namespace usa
191217 * @return bool : Return true if the string is an uppercase string,
192218 * else false.
193219 ************************************************************************/
194- __BOOL__ is_upper ();
220+ __BOOL__ is_upper () const ;
195221 /* ***********************************************************************/
196222
197223
@@ -202,7 +228,7 @@ namespace usa
202228 * @return bool : Return true if the string is a lowercase string,
203229 * else false.
204230 ************************************************************************/
205- __BOOL__ is_lower ();
231+ __BOOL__ is_lower () const ;
206232 /* ***********************************************************************/
207233
208234
@@ -213,7 +239,7 @@ namespace usa
213239 * @return bool : Return true if the string is an alphabetic string,
214240 * else false.
215241 ************************************************************************/
216- __BOOL__ is_alpha ();
242+ __BOOL__ is_alpha () const ;
217243 /* ***********************************************************************/
218244
219245
@@ -224,7 +250,7 @@ namespace usa
224250 * @return bool : Return true if the string is an alpha Numeric string,
225251 * else false.
226252 ************************************************************************/
227- __BOOL__ is_alnum ();
253+ __BOOL__ is_alnum () const ;
228254 /* ***********************************************************************/
229255
230256
@@ -235,7 +261,7 @@ namespace usa
235261 * @return bool : Return true if the string is a numeric string,
236262 * else false.
237263 ************************************************************************/
238- __BOOL__ is_numeric ();
264+ __BOOL__ is_numeric () const ;
239265 /* ***********************************************************************/
240266
241267
@@ -245,21 +271,21 @@ namespace usa
245271 * @return bool : Return true if any char in string is space,
246272 * else false.
247273 ************************************************************************/
248- __BOOL__ is_contain_space ();
274+ __BOOL__ is_contain_space () const ;
249275 /* ***********************************************************************/
250276
251277
252278 /* **********************************************************************
253279 * TODO Add optional arguments start and end for slicing.
254- * @name is_contain
255- * @brief take type of chars are return true if string contain those chars,
280+ * @name is_contain_any
281+ * @brief take no. of chars are return true if string contains any of those chars,
256282 * else false.
257- * @param type: contain which type of character. (By default 'special_chars')
258- * @example usa::string("C++ is awesome!").is_contain (punctuation);
259- * @return bool : Return true if the string contains given type of characters,
283+ * @param str: string of different characters.
284+ * @example usa::string("C++ is awesome!").is_contain_any (punctuation);
285+ * @return bool : Return true if the string contains any of those characters,
260286 * else false.
261287 ************************************************************************/
262- __BOOL__ is_contain (const char * type = special_chars) ;
288+ __BOOL__ is_contain_any (const char * str) const ;
263289 /* ***********************************************************************/
264290
265291
@@ -283,7 +309,7 @@ namespace usa
283309 * @return bool : Return true if string ends with the specified suffix,
284310 * else false.
285311 ************************************************************************/
286- __BOOL__ endswith (__STDSTRING__ str, __BOOL__ match_case = true );
312+ __BOOL__ endswith (const __STDSTRING__ & str, __BOOL__ match_case = true );
287313 /* ***********************************************************************/
288314
289315
@@ -298,7 +324,7 @@ namespace usa
298324 * @return bool : Return true if string starts with the specified suffix,
299325 * else false.
300326 ************************************************************************/
301- __BOOL__ startswith (__STDSTRING__ str, __BOOL__ match_case = true );
327+ __BOOL__ startswith (const __STDSTRING__ & str, __BOOL__ match_case = true );
302328 /* ***********************************************************************/
303329
304330
@@ -313,7 +339,7 @@ namespace usa
313339 * @return int : Return the lowest index in string where substring is found,
314340 * Return -1 on failure.
315341 ************************************************************************/
316- __INT__ find_str (__STDSTRING__ str, __INT__ pos = 0 , __BOOL__ match_case = true );
342+ __INT__ find_str (const __STDSTRING__ & str, __INT__ pos = 0 , __BOOL__ match_case = true );
317343 /* ***********************************************************************/
318344
319345
@@ -324,7 +350,8 @@ namespace usa
324350 * @return int : Return the number of occurrences of character @c 'ch'
325351 * in string.
326352 ************************************************************************/
327- __INT__ count (__CHAR__ ch);
353+ __INT__ count (const __CHAR__ &ch) const ;
354+ __INT__ countWord (string word, bool match_case = true ) const ;
328355 /* ***********************************************************************/
329356
330357
@@ -362,13 +389,10 @@ namespace usa
362389 * @return usa::string& : Return a refrence of Concatenated string.
363390 ************************************************************************/
364391 template <size_t n>
365- __MYSTRING_REF__ join (string(&arr)[n], string delimiter = "", __BOOL__ swd = true)
392+ __MYSTRING_REF__ join (string(&arr)[n], const string & delimiter = "", __BOOL__ swd = true)
366393 {
367394 for (int i = 0 ; i < n; i++)
368- if (swd)
369- (*this ) += delimiter + arr[i];
370- else
371- (*this ) += arr[i] + delimiter;
395+ (*this ) += (swd) ? delimiter + arr[i] : arr[i] + delimiter;
372396 return *this ;
373397 }
374398 /* ***********************************************************************/
@@ -385,13 +409,10 @@ namespace usa
385409 * @return usa::string& : Return a refrence of Concatenated string.
386410 ************************************************************************/
387411 template <size_t n>
388- __MYSTRING_REF__ join (__STDSTRING__(&arr)[n], string delimiter = "", __BOOL__ swd = true)
412+ __MYSTRING_REF__ join (__STDSTRING__(&arr)[n], const string & delimiter = "", __BOOL__ swd = true)
389413 {
390414 for (int i = 0 ; i < n; i++)
391- if (swd)
392- (*this ) += delimiter + arr[i];
393- else
394- (*this ) += arr[i] + delimiter;
415+ (*this ) += (swd) ? delimiter + arr[i] : arr[i] + delimiter;
395416 return *this ;
396417 }
397418 /* ***********************************************************************/
@@ -490,7 +511,7 @@ namespace usa
490511 * @return usa::string& : Return a refrence string with all occurrences
491512 * of @c _old character replaced by @c _new character.
492513 ************************************************************************/
493- __MYSTRING_REF__ replace (__CHAR__ _old, __CHAR__ _new);
514+ __MYSTRING_REF__ replace (const __CHAR__ & _old, const __CHAR__ & _new);
494515 /* ***********************************************************************/
495516
496517
@@ -505,7 +526,7 @@ namespace usa
505526 * @return usa::string& : Return a refrence string with only first occurrences
506527 * of @c _old character replaced by @c _new character.
507528 ************************************************************************/
508- __MYSTRING_REF__ replace_first (__CHAR__ _old, __CHAR__ _new);
529+ __MYSTRING_REF__ replace_first (const __CHAR__ & _old, const __CHAR__ & _new);
509530 /* ***********************************************************************/
510531
511532
@@ -519,7 +540,7 @@ namespace usa
519540 * @return usa::string& : Return a refrence string with all occurrences
520541 * of @c _old substrings replaced by @c _new substring.
521542 ************************************************************************/
522- __MYSTRING_REF__ replace (__STDSTRING__ _old, __STDSTRING__ _new);
543+ __MYSTRING_REF__ replace (const __STDSTRING__ & _old, const __STDSTRING__ & _new);
523544 /* ***********************************************************************/
524545
525546
@@ -534,7 +555,7 @@ namespace usa
534555 * @return usa::string& : Return a refrence string with only first occurrences
535556 * of @c _old substring replaced by @c _new substring.
536557 ************************************************************************/
537- __MYSTRING_REF__ replace_first (__STDSTRING__ _old, __STDSTRING__ _new);
558+ __MYSTRING_REF__ replace_first (const __STDSTRING__ & _old, const __STDSTRING__ & _new);
538559 /* ***********************************************************************/
539560
540561
@@ -583,7 +604,7 @@ namespace usa
583604 * @param delimiter: By which two strings are joined. (By default "")
584605 * @return usa::string& : Return a refrence of Concatenated string.
585606 ************************************************************************/
586- __MYSTRING_REF__ join (const usa::string& obj, string delimiter = " " );
607+ __MYSTRING_REF__ join (const usa::string& obj, const string & delimiter = " " );
587608 /* ***********************************************************************/
588609
589610
@@ -597,7 +618,7 @@ namespace usa
597618 * delimeter, else start with given vactor's element (By default 'true')
598619 * @return usa::string& : Return a refrence of Concatenated string.
599620 ************************************************************************/
600- __MYSTRING_REF__ join (std::vector<__CHAR__> arr, string delimiter = " " , __BOOL__ swd = true );
621+ __MYSTRING_REF__ join (const std::vector<__CHAR__> & arr, const string & delimiter = " " , __BOOL__ swd = true );
601622 /* ***********************************************************************/
602623
603624
@@ -611,7 +632,7 @@ namespace usa
611632 * delimeter, else start with given vactor's element (By default 'true')
612633 * @return usa::string& : Return a refrence of Concatenated string.
613634 ************************************************************************/
614- __MYSTRING_REF__ join (std::vector<string> arr, string delimiter = " " , __BOOL__ swd = true );
635+ __MYSTRING_REF__ join (const std::vector<string> & arr, const string & delimiter = " " , __BOOL__ swd = true );
615636 /* ***********************************************************************/
616637
617638
@@ -625,7 +646,7 @@ namespace usa
625646 * delimeter, else start with given vactor's element (By default 'true')
626647 * @return usa::string& : Return a refrence of Concatenated string.
627648 ************************************************************************/
628- __MYSTRING_REF__ join (std::vector<__STDSTRING__> arr, string delimiter = " " , __BOOL__ swd = true );
649+ __MYSTRING_REF__ join (const std::vector<__STDSTRING__> & arr, const string & delimiter = " " , __BOOL__ swd = true );
629650 /* ***********************************************************************/
630651
631652
@@ -639,7 +660,7 @@ namespace usa
639660 * delimeter, else start with given initializer_list's element (By default 'true')
640661 * @return usa::string& : Return a refrence of Concatenated string.
641662 ************************************************************************/
642- __MYSTRING_REF__ join (std::initializer_list<string> arr, string delimiter = " " , __BOOL__ swd = true );
663+ __MYSTRING_REF__ join (const std::initializer_list<string> & arr, const string & delimiter = " " , __BOOL__ swd = true );
643664 /* ***********************************************************************/
644665
645666
@@ -659,12 +680,12 @@ namespace usa
659680 /* **********************************************************************
660681 * @name split
661682 * @brief Return a vector of the words in the string, using the delimiter to split the string.
662- * The default value of delimiter (" ") means split according to any whitespace.
683+ * The default value of delimiter 0x020 means split according to any whitespace.
663684 *
664- * @param delimiter: By which function split the given string (By default " " ).
685+ * @param delimiter: By which function split the given string (By default ' ' ).
665686 * @return vector std::string : Return a vector of splited tokens of string.
666687 ************************************************************************/
667- vector<__STDSTRING__> split (const char * delimiter = " " );
688+ vector<__STDSTRING__> split (const __CHAR__& delimiter = 0x020 );
668689 /* ***********************************************************************/
669690
670691
0 commit comments