chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt

This commit is contained in:
Selfhosting Dev
2025-09-17 07:43:07 +09:00
parent fcf8ce1f3c
commit adbb0201a9
385 changed files with 35622 additions and 15004 deletions

View File

@ -2,12 +2,12 @@
// Nyashの箱システムによる正規表現処理を提供します。
// 参考: 既存Boxの設計思想
use regex::Regex;
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
use crate::box_trait::{BoolBox, BoxBase, BoxCore, NyashBox, StringBox};
use crate::boxes::array::ArrayBox;
use regex::Regex;
use std::any::Any;
use std::sync::Arc;
use std::fmt::Debug;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct RegexBox {
@ -31,13 +31,13 @@ impl RegexBox {
pub fn pattern(&self) -> &str {
&self.pattern
}
/// パターンマッチテスト
pub fn test(&self, text: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
let text_str = text.to_string_box().value;
Box::new(BoolBox::new(self.is_match(&text_str)))
}
/// マッチ箇所を検索
pub fn find(&self, text: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
let text_str = text.to_string_box().value;
@ -47,36 +47,40 @@ impl RegexBox {
Box::new(crate::boxes::null_box::NullBox::new())
}
}
/// すべてのマッチを検索
pub fn find_all(&self, text: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
let text_str = text.to_string_box().value;
let array = ArrayBox::new();
for mat in self.regex.find_iter(&text_str) {
let _ = array.push(Box::new(StringBox::new(mat.as_str())));
}
Box::new(array)
}
/// 文字列置換
pub fn replace(&self, text: Box<dyn NyashBox>, replacement: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
pub fn replace(
&self,
text: Box<dyn NyashBox>,
replacement: Box<dyn NyashBox>,
) -> Box<dyn NyashBox> {
let text_str = text.to_string_box().value;
let replacement_str = replacement.to_string_box().value;
let result = self.regex.replace_all(&text_str, replacement_str.as_str());
Box::new(StringBox::new(&result.to_string()))
}
/// 文字列分割
pub fn split(&self, text: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
let text_str = text.to_string_box().value;
let array = ArrayBox::new();
for part in self.regex.split(&text_str) {
let _ = array.push(Box::new(StringBox::new(part)));
}
Box::new(array)
}
}
@ -85,7 +89,7 @@ impl NyashBox for RegexBox {
fn clone_box(&self) -> Box<dyn NyashBox> {
Box::new(self.clone())
}
/// 仮実装: clone_boxと同じ後で修正
fn share_box(&self) -> Box<dyn NyashBox> {
self.clone_box()
@ -95,12 +99,10 @@ impl NyashBox for RegexBox {
StringBox::new(format!("RegexBox({})", self.pattern.as_str()))
}
fn type_name(&self) -> &'static str {
"RegexBox"
}
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
if let Some(other_regex) = other.as_any().downcast_ref::<RegexBox>() {
BoolBox::new(self.pattern.as_str() == other_regex.pattern.as_str())
@ -114,7 +116,7 @@ impl BoxCore for RegexBox {
fn box_id(&self) -> u64 {
self.base.id
}
fn parent_type_id(&self) -> Option<std::any::TypeId> {
self.base.parent_type_id
}
@ -122,11 +124,11 @@ impl BoxCore for RegexBox {
fn fmt_box(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "RegexBox({})", self.pattern.as_str())
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}