aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pseudocode-lib/README.md2
-rw-r--r--pseudocode-lib/_exp_string.cc13
-rw-r--r--pseudocode-lib/_exp_string.cps10
-rw-r--r--tests/library/exp-string/expected.txt5
-rw-r--r--tests/library/exp-string/notes.md2
-rw-r--r--tests/library/exp-string/program.cps14
6 files changed, 46 insertions, 0 deletions
diff --git a/pseudocode-lib/README.md b/pseudocode-lib/README.md
index 55367d0..8049ede 100644
--- a/pseudocode-lib/README.md
+++ b/pseudocode-lib/README.md
@@ -24,3 +24,5 @@ The library provides `&`, `_EXP_STRING_NUM_TO_STR` (INTEGER/REAL), `_EXP_STRING_
`_EXP_STRING_RIGHT(S : _EXP_STRING, Count : INTEGER)` returns a new `_EXP_STRING` containing up to Count bytes from the end. Nonpositive counts return an empty string; counts exceeding the length return the whole string. Embedded NUL bytes are preserved.
`_EXP_STRING_MID(S : _EXP_STRING, Start : INTEGER, Count : INTEGER)` returns a new `_EXP_STRING` containing up to Count bytes from the one-based Start position. Starts below 1 clamp to 1; starts beyond the end and nonpositive counts return an empty string. Counts clamp to the remaining bytes. Embedded NUL bytes are preserved.
+
+`_EXP_STRING_LCASE(S : _EXP_STRING)` returns a new `_EXP_STRING` with letters converted to lower case. Its `(Ch : CHAR)` overload returns CHAR, following guide section 5.5. Nonletters and embedded NUL bytes are preserved; the source is unchanged. Use ASCII for predictable case conversion.
diff --git a/pseudocode-lib/_exp_string.cc b/pseudocode-lib/_exp_string.cc
index d406274..6155319 100644
--- a/pseudocode-lib/_exp_string.cc
+++ b/pseudocode-lib/_exp_string.cc
@@ -1,4 +1,5 @@
#include <algorithm>
+#include <cctype>
#include <cstdio>
#include <exception>
#include <stdexcept>
@@ -88,6 +89,18 @@ void _exp_string_impl_mid(void *Target, void *Handle, long long Start, long long
text(Target) = Source.substr(Position, Length);
});
}
+void _exp_string_impl_lcase(void *Target, void *Handle) {
+ checked([&] {
+ text(Target) = text(Handle);
+ for (char &Ch : text(Target))
+ Ch = static_cast<char>(std::tolower(static_cast<unsigned char>(Ch)));
+ });
+}
+char _exp_string_impl_lcase_char(char Ch) {
+ return checked([&] {
+ return static_cast<char>(std::tolower(static_cast<unsigned char>(Ch)));
+ });
+}
void _exp_string_impl_output(void *Handle) {
checked([&] {
const auto &Text = text(Handle);
diff --git a/pseudocode-lib/_exp_string.cps b/pseudocode-lib/_exp_string.cps
index 30eef71..a25b3ef 100644
--- a/pseudocode-lib/_exp_string.cps
+++ b/pseudocode-lib/_exp_string.cps
@@ -17,6 +17,8 @@ EXTERN "C" EXTERN_FUNCTION _exp_string_impl_length(_EXP_STRING_HANDLE) RETURNS _
EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_left(_EXP_STRING_HANDLE, _EXP_STRING_HANDLE, _EXP_STRING_C_INTEGER)
EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_right(_EXP_STRING_HANDLE, _EXP_STRING_HANDLE, _EXP_STRING_C_INTEGER)
EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_mid(_EXP_STRING_HANDLE, _EXP_STRING_HANDLE, _EXP_STRING_C_INTEGER, _EXP_STRING_C_INTEGER)
+EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_lcase(_EXP_STRING_HANDLE, _EXP_STRING_HANDLE)
+EXTERN "C" EXTERN_FUNCTION _exp_string_impl_lcase_char(C_CHAR) RETURNS C_CHAR
EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_output(_EXP_STRING_HANDLE)
CLASS _EXP_STRING
@@ -83,3 +85,11 @@ FUNCTION _EXP_STRING_MID(S : _EXP_STRING, Start : INTEGER, Count : INTEGER) RETU
CALL _exp_string_impl_mid(Result._HANDLE, S._HANDLE, (_EXP_STRING_C_INTEGER)Start, (_EXP_STRING_C_INTEGER)Count)
RETURN Result
ENDFUNCTION
+OVERLOAD FUNCTION _EXP_STRING_LCASE(S : _EXP_STRING) RETURNS _EXP_STRING
+ DECLARE Result : _EXP_STRING
+ CALL _exp_string_impl_lcase(Result._HANDLE, S._HANDLE)
+ RETURN Result
+ENDFUNCTION
+OVERLOAD FUNCTION _EXP_STRING_LCASE(Ch : CHAR) RETURNS CHAR
+ RETURN (CHAR)_exp_string_impl_lcase_char((C_CHAR)Ch)
+ENDFUNCTION
diff --git a/tests/library/exp-string/expected.txt b/tests/library/exp-string/expected.txt
index a3ce792..f5eda62 100644
--- a/tests/library/exp-string/expected.txt
+++ b/tests/library/exp-string/expected.txt
@@ -22,3 +22,8 @@ GH
0:0
0:0
4
+abc@19
+AbC@19
+w:w:@
+0:8
+abc
diff --git a/tests/library/exp-string/notes.md b/tests/library/exp-string/notes.md
index c05d6d7..47fb6ca 100644
--- a/tests/library/exp-string/notes.md
+++ b/tests/library/exp-string/notes.md
@@ -11,3 +11,5 @@ RIGHT keeps FGH, returns zero bytes for an empty source or nonpositive count, an
The added checks use separate procedures to keep generated temporary-object cleanup small enough for the ordinary runner timeout.
MID positions 2..4 give BCD. The minimum INTEGER start clamps to 1 and gives AB; a maximum count from position 7 gives GH. Empty input, a maximum start, and nonpositive counts give length zero. Four bytes starting at the second of three NULs retain two NULs and AB.
+
+LCASE converts AbC@19 to abc@19 without modifying the source. Its CHAR overload returns CHAR w for W or w and preserves @, as in guide section 5.5. Empty length stays zero; two leading NULs survive conversion and letters after them still become abc.
diff --git a/tests/library/exp-string/program.cps b/tests/library/exp-string/program.cps
index 0b6c977..2e041ec 100644
--- a/tests/library/exp-string/program.cps
+++ b/tests/library/exp-string/program.cps
@@ -42,6 +42,7 @@ DELETE Heap
CALL CheckLeft()
CALL CheckRight()
CALL CheckMid()
+CALL CheckLCase()
PROCEDURE CheckLeft()
DECLARE Letters : _EXP_STRING((C_STRING)"ABCDEFGH")
@@ -76,3 +77,16 @@ PROCEDURE CheckMid()
OUTPUT _EXP_STRING_LENGTH(_EXP_STRING_MID(Letters, 2, 0)), ":", _EXP_STRING_LENGTH(_EXP_STRING_MID(Letters, 2, -1))
OUTPUT _EXP_STRING_LENGTH(_EXP_STRING_MID(Nuls & Letters, 2, 4))
ENDPROCEDURE
+
+PROCEDURE CheckLCase()
+ DECLARE Mixed : _EXP_STRING((C_STRING)"AbC@19")
+ DECLARE Empty : _EXP_STRING
+ DECLARE Nuls : _EXP_STRING(2, (C_CHAR)'\0')
+ CALL _EXP_STRING_OUTPUT(_EXP_STRING_LCASE(Mixed))
+ CALL _EXP_STRING_OUTPUT(Mixed)
+ DECLARE Lower : CHAR
+ Lower <- _EXP_STRING_LCASE('W')
+ OUTPUT Lower, ":", _EXP_STRING_LCASE('w'), ":", _EXP_STRING_LCASE('@')
+ OUTPUT _EXP_STRING_LENGTH(_EXP_STRING_LCASE(Empty)), ":", _EXP_STRING_LENGTH(_EXP_STRING_LCASE(Nuls & Mixed))
+ CALL _EXP_STRING_OUTPUT(_EXP_STRING_MID(_EXP_STRING_LCASE(Nuls & Mixed), 3, 3))
+ENDPROCEDURE