Skip to content

Commit

Permalink
Updated String class.
Browse files Browse the repository at this point in the history
  • Loading branch information
end2endzone committed Jan 1, 2022
1 parent 88722ad commit 2792c81
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 2 deletions.
61 changes: 59 additions & 2 deletions include/shellanything/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* SOFTWARE.
*********************************************************************************/

#ifndef SA_STRING_H
#define SA_STRING_H

namespace shellanything
{

Expand All @@ -33,6 +36,7 @@
public:
String();
String(const char* str);
String(const char* str, const size_t count);
String(const String& str);
virtual ~String();

Expand All @@ -48,6 +52,16 @@
bool operator!=(const String& str) const;
String& operator+=(const char* str);
String& operator+=(const String& str);
String operator+(const char* str);
String operator+(const String& str);
bool operator< (const char* str) const;
bool operator< (const String& str) 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;
bool operator>= (const char* str) const;
bool operator>= (const String& str) const;

/// <summary>
/// Get the internal value of the string.
Expand All @@ -74,7 +88,14 @@
inline void clear() { Clear(); } // for std::vector and std::list code compatibility.

/// <summary>
/// Find a value in the list.
/// Reserve an amount of memory for the string.
/// </summary>
/// <param name="size">Amount of memory to reserve in bytes.</param>
void Reserve(const size_t size);
inline void reserve(const size_t size) { Reserve(size); } // for std::vector and std::list code compatibility.

/// <summary>
/// Find a value in the string.
/// </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>
Expand All @@ -86,7 +107,7 @@
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.
/// Find a value in the string, 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>
Expand All @@ -98,9 +119,45 @@
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.

/// <summary>
/// Appends a value in the string.
/// </summary>
/// <param name="value">A value to find within the string.</param>
/// <param name="count">Maximum length of the appended string.value to find within the string.</param>
void Append(const char value);
void Append(const char* value);
void Append(const char* value, const size_t count);
void Append(const size_t count, const char value);
void Append(const String& value);
inline void append(const char value) { return Append(value); } // for std::vector and std::list code compatibility.
inline void append(const char* value) { return Append(value); } // for std::vector and std::list code compatibility.
inline void append(const char* value, const size_t count) { return Append(value, count); } // for std::vector and std::list code compatibility.
inline void append(const size_t count, const char value) { return Append(count, value); } // for std::vector and std::list code compatibility.
inline void append(const String& value) { return Append(value); } // for std::vector and std::list code compatibility.

private:
struct PImpl;
PImpl* mPImpl;
};


} //namespace shellanything

shellanything::String operator+(const shellanything::String& s1, const shellanything::String& s2);
shellanything::String operator+(const char* s1, const shellanything::String& s2);
shellanything::String operator+(const shellanything::String& s1, const char* s2);
//bool operator< (const char* s1, const shellanything::String& s2);
//bool operator<= (const char* s1, const shellanything::String& s2);
//bool operator> (const char* s1, const shellanything::String& s2);
//bool operator>= (const char* s1, const shellanything::String& s2);

/// <summary>
/// A list of String.
/// </summary>
#define SA_LISTS_CLASS_NAME StringList
#define SA_LISTS_BASE_TYPE String
#include "shellanything/ListsDeclaration.inc"
#undef SA_LISTS_BASE_TYPE
#undef SA_LISTS_CLASS_NAME

#endif //SA_STRING_H
141 changes: 141 additions & 0 deletions src/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ namespace shellanything
mPImpl->str = str;
}

String::String(const char* str, const size_t count)
{
mPImpl = new String::PImpl();
mPImpl->str.append(str, count);
}

String::String(const String& str)
{
mPImpl = new String::PImpl();
Expand Down Expand Up @@ -109,6 +115,60 @@ namespace shellanything
return (*this);
}

String String::operator+(const char* str)
{
String temp = (*this);
temp += str;
return temp;
}

String String::operator+(const String& str)
{
String temp = (*this);
temp += str;
return temp;
}

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;
}

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;
}

const char* String::GetValue() const
{
return mPImpl->str.c_str();
Expand All @@ -129,6 +189,11 @@ namespace shellanything
return mPImpl->str.clear();
}

void String::Reserve(const size_t size)
{
mPImpl->str.reserve(size);
}

size_t String::Find(const char value) const
{
return mPImpl->str.find(value);
Expand Down Expand Up @@ -159,4 +224,80 @@ namespace shellanything
return mPImpl->str.find(value.mPImpl->str, offset);
}

void String::Append(const char value)
{
mPImpl->str.append(1, value);
}

void String::Append(const char* value)
{
mPImpl->str.append(value);
}

void String::Append(const char* value, const size_t count)
{
mPImpl->str.append(value, count);
}

void String::Append(const size_t count, const char value)
{
mPImpl->str.append(count, value);
}

void String::Append(const String& value)
{
mPImpl->str.append(value.mPImpl->str);
}

} //namespace shellanything

shellanything::String operator+(const shellanything::String& s1, const shellanything::String& s2)
{
shellanything::String temp = (s1);
temp += s2;
return temp;
}

shellanything::String operator+(const char* s1, const shellanything::String& s2)
{
shellanything::String temp = (s1);
temp += s2;
return temp;
}

shellanything::String operator+(const shellanything::String& s1, const char* s2)
{
shellanything::String temp = (s1);
temp += s2;
return temp;
}

//bool operator< (const char* s1, const shellanything::String& s2)
//{
// return shellanything::String(s1) < s2;
//}
//
//bool operator<= (const char* s1, const shellanything::String& s2)
//{
// return shellanything::String(s1) <= s2;
//}
//
//bool operator> (const char* s1, const shellanything::String& s2)
//{
// return shellanything::String(s1) > s2;
//}
//
//bool operator>= (const char* s1, const shellanything::String& s2)
//{
// return shellanything::String(s1) >= s2;
//}


/// <summary>
/// A list of String.
/// </summary>
#define SA_LISTS_CLASS_NAME StringList
#define SA_LISTS_BASE_TYPE String
#include "shellanything/ListsBody.inc"
#undef SA_LISTS_BASE_TYPE
#undef SA_LISTS_CLASS_NAME

0 comments on commit 2792c81

Please sign in to comment.