ソースを参照

Removed deprecated split functions.

David Piuva 5 年 前
コミット
d2f2ea63c6

+ 1 - 16
Source/DFPSR/base/text.cpp

@@ -902,7 +902,7 @@ void dsr::string_split_callback(std::function<void(ReadableString)> action, cons
 }
 }
 
 
 // Optimization for string_split
 // Optimization for string_split
-// TODO: Clean up!
+// TODO: Clean up all these functions by constructing String from ReadableString without cloning!
 static String createSubString_shared(const DsrChar *content, int64_t length, const Buffer &buffer, char32_t* writeSection) {
 static String createSubString_shared(const DsrChar *content, int64_t length, const Buffer &buffer, char32_t* writeSection) {
 	String result;
 	String result;
 	result.readSection = content;
 	result.readSection = content;
@@ -976,21 +976,6 @@ List<String> dsr::string_split(const ReadableString& source, DsrChar separator,
 	return result;
 	return result;
 }
 }
 
 
-void dsr::string_dangerous_split_inPlace(List<ReadableString> &target, const ReadableString& source, DsrChar separator, bool appendResult) {
-	if (!appendResult) {
-		target.clear();
-	}
-	string_split_callback([&target](ReadableString section){
-		target.push(section);
-	}, source, separator);
-}
-
-List<ReadableString> dsr::string_dangerous_split(const ReadableString& source, DsrChar separator) {
-	List<ReadableString> result;
-	string_dangerous_split_inPlace(result, source, separator);
-	return result;
-}
-
 int64_t dsr::string_splitCount(const ReadableString& source, DsrChar separator) {
 int64_t dsr::string_splitCount(const ReadableString& source, DsrChar separator) {
 	int64_t result;
 	int64_t result;
 	string_split_callback([&result](ReadableString element) {
 	string_split_callback([&result](ReadableString element) {

+ 3 - 30
Source/DFPSR/base/text.h

@@ -123,6 +123,7 @@ class String : public ReadableString {
 IMPL_ACCESS:
 IMPL_ACCESS:
 	// Same as readSection, but with write access for appending more text
 	// Same as readSection, but with write access for appending more text
 	char32_t* writeSection = nullptr;
 	char32_t* writeSection = nullptr;
+	// TODO: Move into the implementation
 	// Internal constructor
 	// Internal constructor
 	String(Buffer buffer, DsrChar *content, int64_t length);
 	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
 	// 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"
 //   Example: string_after(U"0123456789", 5) == U"6789"
 ReadableString string_after(const ReadableString& source, int64_t exclusiveStart);
 ReadableString string_after(const ReadableString& source, int64_t exclusiveStart);
 
 
-// The safest split implementation
+// Split source into a list of strings.
 // Post-condition:
 // Post-condition:
 //   Returns a list of strings from source by splitting along separator.
 //   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.
 //   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.
 // 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.
 // 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);
 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.
 // 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:
 // Side-effects:
 //   Calls action for each sub-string divided by separator in source.
 //   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);
 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) {
 inline void string_split_callback(const ReadableString& source, DsrChar separator, bool removeWhiteSpace, std::function<void(ReadableString)> action) {
 	string_split_callback(action, source, separator, removeWhiteSpace);
 	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.
 // Split source using separator, only to return the number of splits.
 // Useful for pre-allocation.
 // Useful for pre-allocation.
 int64_t string_splitCount(const ReadableString& source, DsrChar separator);
 int64_t string_splitCount(const ReadableString& source, DsrChar separator);

+ 2 - 2
Source/SDK/sandbox/sprite/spriteAPI.cpp

@@ -34,7 +34,7 @@ struct SpriteConfig {
 				} else if (string_caseInsensitiveMatch(key, U"MaxBound")) {
 				} else if (string_caseInsensitiveMatch(key, U"MaxBound")) {
 					this->maxBound = parseFVector3D(value);
 					this->maxBound = parseFVector3D(value);
 				} else if (string_caseInsensitiveMatch(key, U"Points")) {
 				} else if (string_caseInsensitiveMatch(key, U"Points")) {
-					List<ReadableString> values = string_dangerous_split(value, U',');
+					List<String> values = string_split(value, U',');
 					if (values.length() % 3 != 0) {
 					if (values.length() % 3 != 0) {
 						throwError("Points contained ", values.length(), " values, which is not evenly divisible by three!");
 						throwError("Points contained ", values.length(), " values, which is not evenly divisible by three!");
 					} else {
 					} else {
@@ -45,7 +45,7 @@ struct SpriteConfig {
 						}
 						}
 					}
 					}
 				} else if (string_caseInsensitiveMatch(key, U"TriangleIndices")) {
 				} else if (string_caseInsensitiveMatch(key, U"TriangleIndices")) {
-					List<ReadableString> values = string_dangerous_split(value, U',');
+					List<String> values = string_split(value, U',');
 					if (values.length() % 3 != 0) {
 					if (values.length() % 3 != 0) {
 						throwError("TriangleIndices contained ", values.length(), " values, which is not evenly divisible by three!");
 						throwError("TriangleIndices contained ", values.length(), " values, which is not evenly divisible by three!");
 					} else {
 					} else {

+ 1 - 1
Source/SDK/sandbox/sprite/spriteAPI.h

@@ -12,7 +12,7 @@ namespace dsr {
 
 
 // TODO: Make into a constructor for each vector type
 // TODO: Make into a constructor for each vector type
 inline FVector3D parseFVector3D(const ReadableString& content) {
 inline FVector3D parseFVector3D(const ReadableString& content) {
-	List<ReadableString> args = string_dangerous_split(content, U',');
+	List<String> args = string_split(content, U',');
 	if (args.length() != 3) {
 	if (args.length() != 3) {
 		printText("Expected a vector of three decimal values.\n");
 		printText("Expected a vector of three decimal values.\n");
 		return FVector3D();
 		return FVector3D();

+ 5 - 8
Source/SDK/sandbox/tool.cpp

@@ -387,7 +387,7 @@ static void loadPlyModel(ParserState& state, const ReadableString& content, bool
 	int startPointIndex = model_getNumberOfPoints(targetModel);
 	int startPointIndex = model_getNumberOfPoints(targetModel);
 	int targetPart = shadow ? 0 : state.part;
 	int targetPart = shadow ? 0 : state.part;
 	// Split lines
 	// Split lines
-	List<ReadableString> lines = string_dangerous_split(content, U'\n');
+	List<String> lines = string_split(content, U'\n', true);
 	List<PlyElement> elements;
 	List<PlyElement> elements;
 	bool readingContent = false; // True after passing end_header
 	bool readingContent = false; // True after passing end_header
 	int elementIndex = -1; // current member of elements
 	int elementIndex = -1; // current member of elements
@@ -407,9 +407,7 @@ static void loadPlyModel(ParserState& state, const ReadableString& content, bool
 	}
 	}
 	for (int l = 0; l < lines.length(); l++) {
 	for (int l = 0; l < lines.length(); l++) {
 		// Tokenize the current line
 		// Tokenize the current line
-		ReadableString currentLine = string_removeOuterWhiteSpace(lines[l]);
-		List<ReadableString> tokens;
-		string_dangerous_split_inPlace(tokens, currentLine, U' ');
+		List<String> tokens = string_split(lines[l], U' ');
 		if (tokens.length() > 0 && !string_caseInsensitiveMatch(tokens[0], U"COMMENT")) {
 		if (tokens.length() > 0 && !string_caseInsensitiveMatch(tokens[0], U"COMMENT")) {
 			if (readingContent) {
 			if (readingContent) {
 				// Parse geometry
 				// Parse geometry
@@ -691,7 +689,7 @@ static ImageRgbaU8 createDebugTexture() {
 }
 }
 ImageRgbaU8 debugTexture = createDebugTexture();
 ImageRgbaU8 debugTexture = createDebugTexture();
 
 
-static void parse_shape(ParserState& state, List<ReadableString>& args, bool shadow) {
+static void parse_shape(ParserState& state, List<String>& args, bool shadow) {
 	if (state.part == -1) {
 	if (state.part == -1) {
 		printText("    Cannot generate a ", args[0], " without a part.\n");
 		printText("    Cannot generate a ", args[0], " without a part.\n");
 	}
 	}
@@ -723,8 +721,7 @@ static void parse_shape(ParserState& state, List<ReadableString>& args, bool sha
 }
 }
 
 
 static void parse_dsm(ParserState& state, const ReadableString& content) {
 static void parse_dsm(ParserState& state, const ReadableString& content) {
-	List<ReadableString> lines = string_dangerous_split(content, U'\n');
-	List<ReadableString> args; // Reusing the buffer for in-place splitting of arguments on each line
+	List<String> lines = string_split(content, U'\n');
 	for (int l = 0; l < lines.length(); l++) {
 	for (int l = 0; l < lines.length(); l++) {
 		// Get the current line
 		// Get the current line
 		ReadableString line = lines[l];
 		ReadableString line = lines[l];
@@ -746,7 +743,7 @@ static void parse_dsm(ParserState& state, const ReadableString& content) {
 			} else if (colonIndex > -1) {
 			} else if (colonIndex > -1) {
 				ReadableString command = string_removeOuterWhiteSpace(string_before(line, colonIndex));
 				ReadableString command = string_removeOuterWhiteSpace(string_before(line, colonIndex));
 				ReadableString argContent = string_after(line, colonIndex);
 				ReadableString argContent = string_after(line, colonIndex);
-				string_dangerous_split_inPlace(args, argContent, U',');
+				List<String> args = string_split(argContent, U',');
 				for (int a = 0; a < args.length(); a++) {
 				for (int a = 0; a < args.length(); a++) {
 					args[a] = string_removeOuterWhiteSpace(args[a]);
 					args[a] = string_removeOuterWhiteSpace(args[a]);
 				}
 				}