From a1ba45b28c94244d2e1c6f00372d51d294cc3edc Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 20 Oct 2026 11:01:52 +0000 Subject: feat(library): add experimental string LCASE overloads Co-Authored-By: Claude Opus 5.5 --- pseudocode-lib/README.md | 2 ++ pseudocode-lib/_exp_string.cc | 13 +++++++++++++ pseudocode-lib/_exp_string.cps | 10 ++++++++++ 3 files changed, 25 insertions(+) (limited to 'pseudocode-lib') 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 +#include #include #include #include @@ -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(std::tolower(static_cast(Ch))); + }); +} +char _exp_string_impl_lcase_char(char Ch) { + return checked([&] { + return static_cast(std::tolower(static_cast(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 -- cgit v1.3.1-4-g156e