-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a String class to replace std::string. For #102.
- Loading branch information
1 parent
af0dd4d
commit 88722ad
Showing
6 changed files
with
463 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/********************************************************************************** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Antoine Beauchamp | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*********************************************************************************/ | ||
|
||
namespace shellanything | ||
{ | ||
|
||
/// <summary> | ||
/// A structure that contains a list of Configuration class pointers. | ||
/// </summary> | ||
class String | ||
{ | ||
public: | ||
String(); | ||
String(const char* str); | ||
String(const String& str); | ||
virtual ~String(); | ||
|
||
static const size_t INVALID_INDEX = (size_t)-1; | ||
|
||
String& operator=(const char* str); | ||
String& operator=(const String& str); | ||
char & operator[](size_t index); | ||
const char& operator[](size_t index) const; | ||
bool operator==(const char* str) const; | ||
bool operator==(const String& str) const; | ||
bool operator!=(const char* str) const; | ||
bool operator!=(const String& str) const; | ||
String& operator+=(const char* str); | ||
String& operator+=(const String& str); | ||
|
||
/// <summary> | ||
/// Get the internal value of the string. | ||
/// </summary> | ||
const char* GetValue() const; | ||
inline const char * c_str() const { return GetValue(); } // for std::vector and std::list code compatibility. | ||
|
||
/// <summary> | ||
/// Define if the string is empty. | ||
/// </summary> | ||
bool IsEmpty() const; | ||
inline bool empty() const { return IsEmpty(); } // for std::vector and std::list code compatibility. | ||
|
||
/// <summary> | ||
/// Get the length of the string. | ||
/// </summary> | ||
size_t GetSize() const; | ||
inline size_t size() const { return GetSize(); } // for std::vector and std::list code compatibility. | ||
|
||
/// <summary> | ||
/// Empty the string. | ||
/// </summary> | ||
void Clear(); | ||
inline void clear() { Clear(); } // for std::vector and std::list code compatibility. | ||
|
||
/// <summary> | ||
/// Find a value in the list. | ||
/// </summary> | ||
/// <param name="value">A value to find within the string.</param> | ||
/// <returns>Returns the position where the search value was found. Returns INVALID_INDEX otherwise.</returns> | ||
size_t Find(const char value) const; | ||
size_t Find(const char * value) const; | ||
size_t Find(const String & value) const; | ||
inline size_t find(const char value) const { return Find(value); } // for std::vector and std::list code compatibility. | ||
inline size_t find(const char* value) const { return Find(value); } // for std::vector and std::list code compatibility. | ||
inline size_t find(const String& value) const { return Find(value); } // for std::vector and std::list code compatibility. | ||
|
||
/// <summary> | ||
/// Find a value in the list, starting at the given offset. | ||
/// </summary> | ||
/// <param name="value">A value to find within the string.</param> | ||
/// <param name="offset">Position at which the search must start.</param> | ||
/// <returns>Returns the position where the search value was found. Returns INVALID_INDEX otherwise.</returns> | ||
size_t Find(const char value, size_t offset) const; | ||
size_t Find(const char * value, size_t offset) const; | ||
size_t Find(const String & value, size_t offset) const; | ||
inline size_t find(const char value, size_t offset) const { return Find(value, offset); } // for std::vector and std::list code compatibility. | ||
inline size_t find(const char* value, size_t offset) const { return Find(value, offset); } // for std::vector and std::list code compatibility. | ||
inline size_t find(const String& value, size_t offset) const { return Find(value, offset); } // for std::vector and std::list code compatibility. | ||
|
||
private: | ||
struct PImpl; | ||
PImpl* mPImpl; | ||
}; | ||
|
||
} //namespace shellanything |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/********************************************************************************** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Antoine Beauchamp | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*********************************************************************************/ | ||
|
||
#include "shellanything/String.h" | ||
#include <string> | ||
|
||
namespace shellanything | ||
{ | ||
|
||
struct String::PImpl | ||
{ | ||
std::string str; | ||
}; | ||
|
||
String::String() | ||
{ | ||
mPImpl = new String::PImpl(); | ||
} | ||
|
||
String::String(const char* str) | ||
{ | ||
mPImpl = new String::PImpl(); | ||
mPImpl->str = str; | ||
} | ||
|
||
String::String(const String& str) | ||
{ | ||
mPImpl = new String::PImpl(); | ||
mPImpl->str = str.mPImpl->str; | ||
} | ||
|
||
String::~String() | ||
{ | ||
delete mPImpl; | ||
} | ||
|
||
String& String::operator=(const char* str) | ||
{ | ||
mPImpl->str = str; | ||
return (*this); | ||
} | ||
|
||
String& String::operator=(const String& str) | ||
{ | ||
mPImpl->str = str.mPImpl->str; | ||
return (*this); | ||
} | ||
|
||
char& String::operator[](size_t index) | ||
{ | ||
return mPImpl->str[index]; | ||
} | ||
|
||
const char& String::operator[](size_t index) const | ||
{ | ||
return mPImpl->str[index]; | ||
} | ||
|
||
bool String::operator==(const char* str) const | ||
{ | ||
return mPImpl->str == str; | ||
} | ||
|
||
bool String::operator==(const String& str) const | ||
{ | ||
return mPImpl->str == str.mPImpl->str; | ||
} | ||
|
||
bool String::operator!=(const char* str) const | ||
{ | ||
return mPImpl->str != str; | ||
} | ||
|
||
bool String::operator!=(const String& str) const | ||
{ | ||
return mPImpl->str != str.mPImpl->str; | ||
} | ||
|
||
String& String::operator+=(const char* str) | ||
{ | ||
mPImpl->str += str; | ||
return (*this); | ||
} | ||
|
||
String& String::operator+=(const String& str) | ||
{ | ||
mPImpl->str += str.mPImpl->str; | ||
return (*this); | ||
} | ||
|
||
const char* String::GetValue() const | ||
{ | ||
return mPImpl->str.c_str(); | ||
} | ||
|
||
bool String::IsEmpty() const | ||
{ | ||
return mPImpl->str.empty(); | ||
} | ||
|
||
size_t String::GetSize() const | ||
{ | ||
return mPImpl->str.size(); | ||
} | ||
|
||
void String::Clear() | ||
{ | ||
return mPImpl->str.clear(); | ||
} | ||
|
||
size_t String::Find(const char value) const | ||
{ | ||
return mPImpl->str.find(value); | ||
} | ||
|
||
size_t String::Find(const char* value) const | ||
{ | ||
return mPImpl->str.find(value); | ||
} | ||
|
||
size_t String::Find(const String& value) const | ||
{ | ||
return mPImpl->str.find(value.mPImpl->str); | ||
} | ||
|
||
size_t String::Find(const char value, size_t offset) const | ||
{ | ||
return mPImpl->str.find(value, offset); | ||
} | ||
|
||
size_t String::Find(const char* value, size_t offset) const | ||
{ | ||
return mPImpl->str.find(value, offset); | ||
} | ||
|
||
size_t String::Find(const String& value, size_t offset) const | ||
{ | ||
return mPImpl->str.find(value.mPImpl->str, offset); | ||
} | ||
|
||
} //namespace shellanything |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.