Browse Source

Removed String's read function to simplify declaration.

David Piuva 5 years ago
parent
commit
1152ac95f2
2 changed files with 8 additions and 9 deletions
  1. 6 8
      Source/DFPSR/base/text.cpp
  2. 2 1
      Source/DFPSR/base/text.h

+ 6 - 8
Source/DFPSR/base/text.cpp

@@ -67,7 +67,7 @@ std::ostream& Printable::toStreamIndented(std::ostream& out, const ReadableStrin
 	String result;
 	this->toStreamIndented(result, indentation);
 	for (int64_t i = 0; i < result.length; i++) {
-		out.put(toAscii(result.read(i)));
+		out.put(toAscii(result.readSection[i]));
 	}
 	return out;
 }
@@ -89,7 +89,7 @@ bool dsr::string_match(const ReadableString& a, const ReadableString& b) {
 		return false;
 	} else {
 		for (int64_t i = 0; i < a.length; i++) {
-			if (a.read(i) != b.read(i)) {
+			if (a.readSection[i] != b.readSection[i]) {
 				return false;
 			}
 		}
@@ -102,7 +102,7 @@ bool dsr::string_caseInsensitiveMatch(const ReadableString& a, const ReadableStr
 		return false;
 	} else {
 		for (int64_t i = 0; i < a.length; i++) {
-			if (towupper(a.read(i)) != towupper(b.read(i))) {
+			if (towupper(a.readSection[i]) != towupper(b.readSection[i])) {
 				return false;
 			}
 		}
@@ -112,7 +112,7 @@ bool dsr::string_caseInsensitiveMatch(const ReadableString& a, const ReadableStr
 
 std::ostream& ReadableString::toStream(std::ostream& out) const {
 	for (int64_t i = 0; i < this->length; i++) {
-		out.put(toAscii(this->read(i)));
+		out.put(toAscii(this->readSection[i]));
 	}
 	return out;
 }
@@ -657,16 +657,14 @@ bool ReadableString::checkBound(int64_t start, int64_t length, bool warning) con
 	}
 }
 
-DsrChar ReadableString::read(int64_t index) const {
+DsrChar ReadableString::operator[] (int64_t index) const {
 	if (index < 0 || index >= this->length) {
-		return '\0';
+		return U'\0';
 	} else {
 		return this->readSection[index];
 	}
 }
 
-DsrChar ReadableString::operator[] (int64_t index) const { return this->read(index); }
-
 ReadableString::ReadableString() {}
 ReadableString::~ReadableString() {}
 

+ 2 - 1
Source/DFPSR/base/text.h

@@ -64,9 +64,10 @@ IMPL_ACCESS:
 	// A local pointer to the sub-allocation
 	const char32_t* readSection = nullptr;
 	// The length of the current string in characters
+	//   Use the string_length getter to access
+	//   If you just want to reuse memory for a sub-string, then use string_inclusiveRange
 	int64_t length = 0;
 public:
-	DsrChar read(int64_t index) const;
 	// Returning the character by value prevents writing to memory that might be a constant literal or shared with other strings
 	DsrChar operator[] (int64_t index) const;
 public: