phase: 20.49 COMPLETE; 20.50 Flow+String minimal reps; 20.51 selfhost v0/v1 minimal (Option A/B); hv1-inline binop/unop/copy; docs + run_all + CURRENT_TASK -> 21.0

This commit is contained in:
nyash-codex
2025-11-06 15:41:52 +09:00
parent 2dc370223d
commit 77d4fd72b3
1658 changed files with 6288 additions and 2612 deletions

61
string_utils_test.hako Normal file
View File

@ -0,0 +1,61 @@
// StringUtils単体テスト
static box StringUtilsTest {
main() {
print("🧪 StringUtils Test")
// シンプルなファクトリーテスト
local text = " hello world "
print("Original: '" + text + "'")
print("Testing trim...")
local result = this.trim(text)
print("Trimmed: '" + result + "'")
print("Testing starts_with...")
local starts = this.starts_with("hello world", "hello")
print("starts_with 'hello': " + starts)
print("✅ StringUtils test complete")
return 0
}
// 基本的なtrim実装
trim(s) {
return this.trim_end(this.trim_start(s))
}
trim_start(s) {
local i = 0
loop(i < s.length()) {
local ch = s.substring(i, i + 1)
if not this.is_whitespace(ch) {
break
}
i = i + 1
}
return s.substring(i, s.length())
}
trim_end(s) {
local i = s.length() - 1
loop(i >= 0) {
local ch = s.substring(i, i + 1)
if not this.is_whitespace(ch) {
break
}
i = i - 1
}
return s.substring(0, i + 1)
}
is_whitespace(ch) {
return ch == " " or ch == "\t" or ch == "\n" or ch == "\r"
}
starts_with(s, prefix) {
if prefix.length() > s.length() {
return false
}
return s.substring(0, prefix.length()) == prefix
}
}