Skip to content

Commit 5da6927

Browse files
author
梶塚太智
committed
Update main.rs
Developed command about decode and encode by Unicode
1 parent 595b19b commit 5da6927

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,29 @@ impl Executor {
429429
self.stack.push(Type::String(text.repeat(count as usize)));
430430
}
431431

432+
// 数値からユニコード文字列を取得
433+
"decode" => {
434+
let code = self.pop_stack().get_number();
435+
let result = char::from_u32(code as u32);
436+
match result {
437+
Some(c) => self.stack.push(Type::String(c.to_string())),
438+
None => {
439+
self.log_print("エラー! 数値デコードに失敗しました".to_string());
440+
self.stack.push(Type::Number(code));
441+
}
442+
}
443+
}
444+
445+
"encode" => {
446+
let string = self.pop_stack().get_string();
447+
if let Some(first_char) = string.chars().next() {
448+
self.stack.push(Type::Number((first_char as u32) as f64));
449+
} else {
450+
self.log_print("エラー! 文字列のエンコードに失敗しました".to_string());
451+
self.stack.push(Type::String(string))
452+
}
453+
}
454+
432455
// 文字列を結合
433456
"concat" => {
434457
let b = self.pop_stack().get_string();

0 commit comments

Comments
 (0)