|
libbio
|
#include <String.h>


Public Types | |
| enum | Mode { INVALID = 0 , READ_ONLY , COPY_ON_WRITE , READ_WRITE , HANDOFF , MODE_MAX } |
Static Public Member Functions | |
| static const char * | GetCloneOf (const char *source, ::std::size_t length=0) |
| static String & | SetMode (const String &string, Mode desiredMode) |
| template<typename T > | |
| static String | From (const T &value) |
Protected Member Functions | |
| virtual void | Clear () |
Protected Attributes | |
| Mode | mMode |
Protected Attributes inherited from bio::ImmutableString | |
| const char * | mString |
| ::std::size_t | mLength |
We use our own String implementation in order to ensure consistency across the library and to provide a single point of optimization for all String operations.
We would like bio::Strings to encompass both the compile-time behavior of std::string_view and run-time versatility of std::string while being fully backwards compatible.
Like other Biology classes, String is inheritable and designed to be extended.
String is implemented as the addition of mutability to ImmutableString by way of a non-trivial destructor with the ability to allocate and delete data.
ImmutableStrings can be used in constexpr while Strings cannot.
Strings have different Modes. These Modes indicate how to handle internal operations.
The Mode of a String is set depending on how it is constructed.
You may change the String::Mode using the static SetMode method, which will produce a new String.
A READ_ONLY String cannot be set by any means. If you wish to edit a READ_ONLY String, you must SetMode first.
A COPY_ON_WRITE String will automatically become a READ_WRITE String when written to.
NOTE: There are no "WRITE" operation for COPY_ON_WRITE to use. This will likely change in a future release.
An empty string will point to NULL, have a length of 0.
You may specify the Mode of an empty String.
Constructing a String from a const char* clones the provided contents into READ_WRITE storage.
Use ImmutableString or View() for borrowed read-only access.
| string |
| bio::String::String | ( | ::std::string | string | ) |
Constructing a String from a std::string basically gives back an std::string.
std::strings can only ever READ_WRITE, since their c_str() method goes out of scope on subsequent access.
| string |
| bio::String::String | ( | const ImmutableString & | string | ) |
ImmutableStrings are treated as const char* and will yield a READ_ONLY String.
| string |
|
virtual |
|
virtual |
Convert "true" or "false" to bool.
This is essentially just {== "true"} with no extra test for "false".
This behavior may change in a future release.
Case insensitive.
Get a new const char* from *this.
YOU MUST delete THE RETURNED VALUE TO AVOID MEMORY LEAKS!
|
virtual |
convert *this to a float.
|
virtual |
convert *this to an integer.
|
virtual |
Convert *this to a number.
Uses the most permissive numeric notation available.
| std::string bio::String::AsStdString | ( | ) | const |
Get *this as an std::string.
|
virtual |
convert *this to an unsigned integer.
|
protectedvirtual |
Will delete mString if *this is READ_WRITE, etc.
Check if *this contains other.
| other |
Check if *this ends with other.
| other |
Converts the given value to a string.
| value |
Copies the contents of source, up to length characters, into a new const char*.
NOTE: because "new" is used here, a delete needs to be called elsewhere.
| source | |
| length | if 0, the whole source is copied. |
|
virtual |
|
virtual |
Check if *this can be cast AsBool().
|
virtual |
Check if this can be cast AsNumber().
In order to make this method more useful than just a simple boolean check, the return format is encoded such that you are given details on the numeric format of *this.
The format is like -?count(\d+).count(\d), where the leading - is optional, first count is the number of digits before the decimal point, and the second count is the number of digits after the decimal point.
A number like 123 would return 3.0f, since it has 3 digits before the decimal point and 0 after.
A number like -1234.567 would return -4.3f, since it has 4 digits before the decimal point and 3 after and is negative.
A number like -.123 would return -0.3f, since it has 0 digits before the decimal point and 3 after.
You can use this to check if *this can be cast as a UInt, etc. (e.g. check = maybeUint.IsNumeric(); check > 1 && !std::fmod(check, 1.0).
|
virtual |
You can implicitly treat Strings as booleans the same way you do pointers (specifically char*).
NOTE: THIS IS NOT this->AsBool()!!!
Append other to *this.
| other |
|
virtual |
|
virtual |
NOTE: Assigning *this an std::string forces it to be READ_WRITE!
| string |
|
virtual |
| toAssign |
NOTE: Mode is NOT copied.
| toCopy |
This is just lies: we const_cast(this) and change the values..
This is used in places where a move operation would be performed but since that can't be done prior to c++11, we hack it.
All Values are moved, including Mode,
| toMoveHack |
| other |
| other |
|
virtual |
NOTE: We ignore Mode when comparing Strings.
| other |
NOTE: We ignore Mode when comparing Strings.
| other |
In order to change the Mode of a String, you must create a new String.
UNDEFINED BEHAVIOR if you:
Check if *this starts with other.
| other |
|
virtual |
Get a smaller string from *this.
| start | |
| end |
| ImmutableString bio::String::View | ( | ) | const |
Get a borrowed read-only view of *this without allocating or copying.
The returned view remains valid until *this is destroyed or mutated in a way that replaces the backing storage.
|
protected |