44
55// / @c Author Usama Azad.
66
7- bool usa::string::is_upper () const
8- {
7+ bool usa::string::is_upper () const {
98 for (const char &ch : *this )
109 if (ch & 0x20 )
1110 return false ;
1211 return true ;
1312}
1413
15- bool usa::string::is_lower () const
16- {
14+ bool usa::string::is_lower () const {
1715 for (const char & ch : *this )
1816 if (!(ch & 0x20 ))
1917 return false ;
2018 return true ;
2119}
2220
23- bool usa::string::is_alpha () const
24- {
25- if (this ->is_contain_space () || this ->is_contain_any (special_chars) || this ->is_None ())
21+ bool usa::string::is_alpha () const {
22+ if (this ->is_containSpace () || this ->is_containAny (punctuation) || this ->isEmpty ())
2623 return false ;
2724 for (int i = 0 ; i < this ->size (); i++)
2825 if (this ->at (i) >= ' 0' && this ->at (i) <= ' 9' )
2926 return false ;
3027 return true ;
3128}
3229
33- bool usa::string::is_alnum () const
34- {
35- return !(this ->is_contain_space () || this ->is_contain_any (special_chars) || this ->is_None ());
30+ bool usa::string::is_alnum () const {
31+ return !(this ->is_containSpace () || this ->is_containAny (punctuation) || this ->isEmpty ());
3632}
3733
38- bool usa::string::is_numeric () const
39- {
40- if (this ->is_contain_space () || this ->is_contain_any (special_chars) || this ->is_None ())
34+ bool usa::string::is_numeric () const {
35+ if (this ->is_containSpace () || this ->is_containAny (punctuation) || this ->isEmpty ())
4136 return false ;
4237 for (int i = 0 ; i < this ->size (); i++)
4338 if (this ->at (i) >= ' a' && this ->at (i) <= ' z' || this ->at (i) >= ' A' && this ->at (i) <= ' Z' )
4439 return false ;
4540 return true ;
4641}
4742
48- bool usa::string::is_space () const
49- {
50- if (this ->is_None ())
43+ bool usa::string::is_space () const {
44+ if (this ->isEmpty ())
5145 return false ;
5246 for (int i = 0 ; i < this ->size (); i++)
5347 if (this ->at (i) != 32 )
5448 return false ;
5549 return true ;
5650}
5751
58- bool usa::string::is_contain_space () const
59- {
60- if (!this ->is_None ())
52+ bool usa::string::is_containSpace () const {
53+ if (!this ->isEmpty ())
6154 for (int i = 0 ; i < this ->size (); i++)
6255 if (this ->at (i) == 32 )
6356 return true ;
6457 return false ;
6558}
6659
67- bool usa::string::is_contain_any (const char *str) const
68- {
69- for (const char &s : std::string (str))
60+ bool usa::string::is_containAny (const char *str) const {
61+ for (const char &s : static_cast <const std::string&>(str))
7062 for (const char &c : *this )
7163 if (c == s)
7264 return true ;
7365 return false ;
7466}
7567
76- bool usa::string::startswith (const std::string& str, bool match_case)
77- {
78- std::string cmp1 = (match_case) ? (*this ) : Lower_Case (*this );
79- std::string cmp2 = (match_case) ? str : Lower_Case (str);
68+ bool usa::string::startswith (const std::string& str, bool match_case) const {
69+ const std::string& cmp1 = (match_case) ? std::string (*this ) : Lower_Case (*this );
70+ const std::string& cmp2 = (match_case) ? str : Lower_Case (str);
8071 for (int i = 0 ; i < cmp2.size (); i++)
8172 if (cmp1[i] != cmp2[i])
8273 return false ;
8374 return true ;
8475}
8576
86- bool usa::string::endswith (const std::string& str, bool match_case)
87- {
88- std::string cmp1 = (match_case) ? (*this ) : Lower_Case (*this );
89- std::string cmp2 = (match_case) ? str : Lower_Case (str);
77+ bool usa::string::endswith (const std::string& str, bool match_case) const {
78+ const std::string& cmp1 = (match_case) ? std::string (*this ) : Lower_Case (*this );
79+ const std::string& cmp2 = (match_case) ? str : Lower_Case (str);
9080 int where = cmp1.size () - cmp2.size (), j = 0 ;
9181 for (int i = where; i < cmp1.size (); i++)
9282 if (cmp1[i] != cmp2[j++])
9383 return false ;
9484 return true ;
9585}
9686
97- int usa::string::count (const char &ch) const
98- {
87+ int usa::string::count (const char &ch) const {
9988 int cnt = 0 ;
10089 for (const char &c : *this )
10190 if (c == ch)
10291 cnt++;
10392 return cnt;
10493}
10594
106- int usa::string::countWord (string word, bool match_case) const
107- {
108- string match = *this ;
95+ int usa::string::countWord (string word, bool match_case) const {
96+ usa::string match = *this ;
10997 if (!match_case){
110- word.toLowerCase ();
111- match.toLowerCase ();
98+ word.toLowerCase_ ();
99+ match.toLowerCase_ ();
112100 }
113101 int cnt = 0 ;
114102 for (const std::string &w : match.split (32 ))
@@ -117,10 +105,9 @@ int usa::string::countWord(string word, bool match_case) const
117105 return cnt;
118106}
119107
120- int usa::string::find_str (const std::string &str, int pos, bool match_case)
121- {
122- std::string cmp1 = (match_case) ? (*this ) : Lower_Case (*this );
123- std::string cmp2 = (match_case) ? str : Lower_Case (str);
108+ int usa::string::findStr (const std::string &str, int pos, bool match_case) const {
109+ const std::string& cmp1 = (match_case) ? std::string (*this ) : Lower_Case (*this );
110+ const std::string& cmp2 = (match_case) ? str : Lower_Case (str);
124111 return (cmp1.find (cmp2, pos) != std::string::npos) ? cmp1.find (cmp2, pos) : -1 ;
125112}
126113
0 commit comments