fix: Kilo/CHIP-8アプリエラー修正 - toInteger, substring, レガシーBox削除
## 修正内容 1. **toIntegerメソッド実装** (#125) - StringBoxにtoInteger()メソッド追加 - box_trait::IntegerBoxを返すよう統一(レガシーboxes::IntegerBox削除) 2. **substringメソッド実装** - StringBoxにsubstring(start, end)メソッド追加 - Kiloエディタで必要な文字列操作を完全サポート 3. **レガシーコード削除** - src/boxes/mod.rsから重複StringBox/IntegerBox/BoolBoxエクスポート削除 - 全てbox_trait実装に統一 4. **プラグインドキュメント整理** - 古い仕様書に「理想案・未実装」「将来構想」明記 - 実装ベースの正確な仕様書作成 - migration-guide.md追加 ## テスト結果 - ✅ Kiloエディタ: 完全動作確認("Enhanced Kilo Editor test complete") - ✅ toInteger()の乗算: 正常動作 - ✅ substring(): 正常動作 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -68,7 +68,7 @@ impl StringBox {
|
||||
|
||||
/// Find substring and return position (or -1 if not found)
|
||||
pub fn find(&self, search: &str) -> Box<dyn NyashBox> {
|
||||
use crate::boxes::IntegerBox;
|
||||
use crate::boxes::integer_box::IntegerBox;
|
||||
match self.value.find(search) {
|
||||
Some(pos) => Box::new(IntegerBox::new(pos as i64)),
|
||||
None => Box::new(IntegerBox::new(-1)),
|
||||
@ -97,19 +97,19 @@ impl StringBox {
|
||||
|
||||
/// Check if string contains substring
|
||||
pub fn contains(&self, search: &str) -> Box<dyn NyashBox> {
|
||||
use crate::boxes::BoolBox;
|
||||
use crate::boxes::bool_box::BoolBox;
|
||||
Box::new(BoolBox::new(self.value.contains(search)))
|
||||
}
|
||||
|
||||
/// Check if string starts with prefix
|
||||
pub fn starts_with(&self, prefix: &str) -> Box<dyn NyashBox> {
|
||||
use crate::boxes::BoolBox;
|
||||
use crate::boxes::bool_box::BoolBox;
|
||||
Box::new(BoolBox::new(self.value.starts_with(prefix)))
|
||||
}
|
||||
|
||||
/// Check if string ends with suffix
|
||||
pub fn ends_with(&self, suffix: &str) -> Box<dyn NyashBox> {
|
||||
use crate::boxes::BoolBox;
|
||||
use crate::boxes::bool_box::BoolBox;
|
||||
Box::new(BoolBox::new(self.value.ends_with(suffix)))
|
||||
}
|
||||
|
||||
@ -127,6 +127,18 @@ impl StringBox {
|
||||
Box::new(StringBox::new(array_box.to_string_box().value))
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert string to integer (parse as i64)
|
||||
pub fn to_integer(&self) -> Box<dyn NyashBox> {
|
||||
use crate::boxes::integer_box::IntegerBox;
|
||||
match self.value.trim().parse::<i64>() {
|
||||
Ok(n) => Box::new(IntegerBox::new(n)),
|
||||
Err(_) => {
|
||||
// If parsing fails, return 0 (JavaScript-like behavior)
|
||||
Box::new(IntegerBox::new(0))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NyashBox for StringBox {
|
||||
|
||||
Reference in New Issue
Block a user