Skip to content

Commit e102fad

Browse files
committed
feat: impl YText
1 parent 687df47 commit e102fad

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

libs/jwst-codec/src/doc/types/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub struct TypeStore {
6464
pub start: Option<StructRef>,
6565
pub map: HashMap<String, StructRef>,
6666
pub item: Option<StructRef>,
67+
pub len: usize,
6768
kind: TypeStoreKind,
6869
}
6970

@@ -75,6 +76,7 @@ impl TypeStore {
7576
start: None,
7677
map: HashMap::new(),
7778
item: None,
79+
len: 0,
7880
kind,
7981
}
8082
}
@@ -86,6 +88,12 @@ impl TypeStore {
8688
}
8789
}
8890

91+
impl From<TypeStore> for TypeStoreRef {
92+
fn from(value: TypeStore) -> Self {
93+
Arc::new(RefCell::new(value))
94+
}
95+
}
96+
8997
impl From<YType> for TypeStore {
9098
fn from(value: YType) -> Self {
9199
match value {

libs/jwst-codec/src/doc/types/text.rs

+35-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1-
use crate::{wrap_inner, Item};
1+
use crate::Item;
22

3-
pub struct YTextInner {
4-
item: Item,
3+
use super::{TypeStore, TypeStoreKind, TypeStoreRef};
4+
5+
pub struct YText {
6+
inner: TypeStoreRef,
7+
}
8+
9+
impl YText {
10+
pub fn new() -> Self {
11+
Self {
12+
inner: TypeStore::new(TypeStoreKind::Text).into(),
13+
}
14+
}
515
}
616

7-
wrap_inner!(YText, YTextInner);
17+
impl From<String> for YText {
18+
fn from(value: String) -> Self {
19+
let mut text = Self::new();
20+
text.insert(0, value);
21+
22+
text
23+
}
24+
}
25+
26+
impl YText {
27+
pub fn len(&self) -> usize {
28+
self.inner.borrow().len
29+
}
30+
31+
pub fn insert(&mut self, index: usize, text: String) {
32+
let pos = self.find_position(index);
33+
}
34+
35+
fn find_position(&self, index: usize) -> Option<Item> {
36+
todo!()
37+
}
38+
}

0 commit comments

Comments
 (0)