Files
c0db/test/strings.c0
2015-04-12 00:33:57 -04:00

30 lines
652 B
Plaintext

#use <conio>
#use <string>
char char_tolower(char c) {
int ccode = char_ord(c);
if (char_ord('A') <= ccode && ccode <= char_ord('Z')) {
int shift = char_ord('a') - char_ord('A');
return char_chr(ccode + shift);
} else {
return c;
}
}
string string_lower(string s)
//@ensures string_length(s) == string_length(\result);
{
int len = string_length(s);
char[] A = string_to_chararray(s);
char[] B = alloc_array(char, len+1);
for (int i = 0; i < len; i++)
B[i] = char_tolower(A[i]);
B[len] = '\0'; /* redundant */
return string_from_chararray(B);
}
int main() {
print (string_lower("HEllo There!?"));
return 0;
}