Introduction
To start off, this library supports UTF-8, 16, and 32 strings. It also supports converting between all three of the encodings. This library also supports all three encodings when using any sort of IO. Even if the operating system's system calls don't use it, this library will convert it for you into the correct encoding that the OS uses so you can continue to use your favorite encoding with less of a hassle.
The best part about this library's strings, is that they come feature packed with all sorts of tools. No need to use another class just to manipulate a string in any way. I like to keep it simple here. However due to the restrictions of the C++ language I did have to implement the UTF conversion methods in a separate class. This decision was made with a lot a thought on how to simplify strings the best, and this was the best outcome.
Not to toot my own horn, but I personally have enjoyed using my own string implementation the best out of any language's support libraries, and I think you will too.
The examples below will only be using UTF-8 strings to demonstrate it's functionality, but everything is 1:1 between all three of the encodings.
Classes
- Str_32 - UTF-32 encoded string
- Str_16 - UTF-16 encoded string
- Str_8 - UTF-8 encoded string
Examples
Size
This method is used to return the size of the string object in characters. There is a single optional Boolean parameter to retrieve the size in bytes.
ehs::Str_8 a = "Hello World!";
ehs::UInt_64 b = a.Size();
Result: b == 12
ehs::Str_8 a = "Hello World!";
ehs::UInt_64 b = a.Size(true);
Result: b == 12
Note: The size in bytes is the same as the size in characters because ASCII is only one byte in UTF-8.
ToLower
This method will turn all English alphabetic characters into their lower case equivalent on the current object.
ehs::Str_8 str = "Hello World!";
str.ToLower();
Result: str == "hello world!"
GetLower
This method will turn all English alphabetic characters into their lower case equivalent on a new string object and return it.
ehs::Str_8 a = "Hello World!";
ehs::Str_8 b = a.GetLower();
Result: b == "hello world!"
ToUpper
This method will turn all English alphabetic characters into their upper case equivalent on the current object.
ehs::Str_8 str = "Hello World!";
str.ToUpper();
Result: str == "HELLO WORLD!"
GetUpper
This method will turn all English alphabetic characters into their upper case equivalent on a new string object and return it.
ehs::Str_8 a = "Hello World!";
ehs::Str_8 b = a.GetUpper();
Result: b == "HELLO WORLD!"
Split
This method will split a single string into multiple strings with the given delimiter and return a Vector container object. The first parameter is the given delimiter to split the string with. The second parameter is the maximum number of times to split the string; this can be set to zero or unassigned a value for unlimited.
ehs::Str_8 a = "Hello! How are you?";
ehs::Vector<ehs::Str_8> b = a.Split(" ", 1);
Result: b == {"Hello!", "How are you?"}
Find
This method will find the first instance of the delimiter. The first parameter is the delimiter. The second parameter is optional but will output the index of where the delimiter was found at, can be null if you don't care for the index. The third parameter is used for optimization, it can search either from left to right, or from right to left. The fourth parameter is the index result, it can be used to output the index at the beginning of the found delimiter or the ending. It returns true if the delimiter has been found, false otherwise.
const Str_8 a = "Hello World!";
UInt_64 i;
if (a.Find("Wo", &i, SearchPattern::RIGHT_LEFT, IndexResult::BEGINNING))
{
Console::Write_8("\"Wo\" found at index " + Str_8::FromNum(i) + ".");
return 0;
}
Console::Write_8("\"Wo\" not found.");
return 1;
Result: i == 6
Basics
Input / Output
System
Welcome to the Wiki.