Skip to content

Commit d7cb91e

Browse files
committed
Added some new functionality
1 parent c3e3eeb commit d7cb91e

File tree

13 files changed

+770
-562
lines changed

13 files changed

+770
-562
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 usastring, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 usastring, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Resources/resmblfun.tcc

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,111 +4,99 @@
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

Resources/resmcon.tcc

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,42 @@
44

55
/// @c Author Usama Azad.
66

7-
int usa::string::to_int()
8-
{
7+
int usa::string::to_int() const {
98
try { return StoI(*this); }
109
catch (...) { return 0; }
1110
}
1211

13-
char usa::string::to_char()
14-
{
12+
char usa::string::to_char() const {
1513
try { return StoC(*this); }
1614
catch (...) { return '\000'; }
1715
}
1816

19-
float usa::string::to_float()
20-
{
17+
float usa::string::to_float() const {
2118
try { return StoF(*this); }
2219
catch (...) { return 0.f; }
2320
}
2421

25-
double usa::string::to_double()
26-
{
22+
double usa::string::to_double() const {
2723
try { return StoD(*this); }
2824
catch (...) { return 0.0; }
2925
}
3026

31-
long usa::string::to_long()
32-
{
27+
long usa::string::to_long() const {
3328
try { return StoL(*this); }
3429
catch (...) { return 0l; }
3530
}
3631

37-
bool usa::string::to_bool()
38-
{
32+
bool usa::string::to_bool() const {
3933
try { return StoB(*this); }
4034
catch (...) { return false; }
4135
}
4236

43-
long double usa::string::to_longdouble()
44-
{
37+
long double usa::string::to_longDouble() const {
4538
try { return StoLD(*this); }
4639
catch (...) { return 0.0L; }
4740
}
4841

49-
std::string usa::string::to_std_string()
50-
{
42+
std::string usa::string::to_stdString() const {
5143
try { return std::string(*this); }
5244
catch (...) { return ""; }
5345
}

0 commit comments

Comments
 (0)