|
|
@@ -123,6 +123,7 @@ class String : public ReadableString {
|
|
|
IMPL_ACCESS:
|
|
|
// Same as readSection, but with write access for appending more text
|
|
|
char32_t* writeSection = nullptr;
|
|
|
+ // TODO: Move into the implementation
|
|
|
// Internal constructor
|
|
|
String(Buffer buffer, DsrChar *content, int64_t length);
|
|
|
// The number of DsrChar characters that can be contained in the allocation before reaching the buffer's end
|
|
|
@@ -239,7 +240,7 @@ ReadableString string_from(const ReadableString& source, int64_t inclusiveStart)
|
|
|
// Example: string_after(U"0123456789", 5) == U"6789"
|
|
|
ReadableString string_after(const ReadableString& source, int64_t exclusiveStart);
|
|
|
|
|
|
-// The safest split implementation
|
|
|
+// Split source into a list of strings.
|
|
|
// Post-condition:
|
|
|
// Returns a list of strings from source by splitting along separator.
|
|
|
// If removeWhiteSpace is true then surrounding white-space will be removed, otherwise white-space is kept.
|
|
|
@@ -247,9 +248,8 @@ ReadableString string_after(const ReadableString& source, int64_t exclusiveStart
|
|
|
// The number of strings returned in the list will equal the number of separating characters plus one, so the result may contain empty strings.
|
|
|
// Each string in the list clones content to its own dynamic buffer. Use string_split_callback if you don't need long term storage.
|
|
|
List<String> string_split(const ReadableString& source, DsrChar separator, bool removeWhiteSpace = false);
|
|
|
-// The fastest and most powerful split implementation
|
|
|
// Split a string without needing a list to store the result.
|
|
|
-// Call it twice using different lambda functions if you want to count the size before allocating a buffer.
|
|
|
+// Use string_splitCount on the same source and separator if you need to know the element count in advance.
|
|
|
// Side-effects:
|
|
|
// Calls action for each sub-string divided by separator in source.
|
|
|
void string_split_callback(std::function<void(ReadableString)> action, const ReadableString& source, DsrChar separator, bool removeWhiteSpace = false);
|
|
|
@@ -257,33 +257,6 @@ void string_split_callback(std::function<void(ReadableString)> action, const Rea
|
|
|
inline void string_split_callback(const ReadableString& source, DsrChar separator, bool removeWhiteSpace, std::function<void(ReadableString)> action) {
|
|
|
string_split_callback(action, source, separator, removeWhiteSpace);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-// TODO: ReadableString is no longer supposed to be unsafe, but String is also meant to be faster.
|
|
|
-
|
|
|
-// Warning! May cause a crash.
|
|
|
-// Do not use a ReadableString generated by splitting a String past the String's lifetime.
|
|
|
-// ReadableString does not allocate any heap memory but is only a view for data allocated elsewhere.
|
|
|
-// Use string_split_callback if you want something safer.
|
|
|
-// Post-condition:
|
|
|
-// Returns a list of strings from source by splitting along separator.
|
|
|
-// The separating characters are excluded from the resulting strings.
|
|
|
-// The number of strings returned in the list will equal the number of separating characters plus one, so the result may contain empty strings.
|
|
|
-// Each string in the list reuses memory from the input string using reference counting, but the list itself will be allocated.
|
|
|
-List<ReadableString> string_dangerous_split(const ReadableString& source, DsrChar separator);
|
|
|
-// Warning! May cause a crash.
|
|
|
-// Do not use a ReadableString generated by splitting a String past the String's lifetime.
|
|
|
-// ReadableString does not allocate any heap memory but is only a view for data allocated elsewhere.
|
|
|
-// Use string_split_callback if you want something safer.
|
|
|
-// Use string_split_inPlace instead of string_split if you want to reuse the memory of an existing list.
|
|
|
-// It will then only allocate when running out of buffer space.
|
|
|
-// Side-effects:
|
|
|
-// Fills the target list with strings from source by splitting along separator.
|
|
|
-// If appendResult is false (default), any pre-existing elements in the target list will be cleared before writing the result.
|
|
|
-// If appendResult is true, the result is appended to the existing target list.
|
|
|
-void string_dangerous_split_inPlace(List<ReadableString> &target, const ReadableString& source, DsrChar separator, bool appendResult = false);
|
|
|
-
|
|
|
-
|
|
|
// Split source using separator, only to return the number of splits.
|
|
|
// Useful for pre-allocation.
|
|
|
int64_t string_splitCount(const ReadableString& source, DsrChar separator);
|