Skip to content

Commit 2e882e3

Browse files
committed
refactor: update function signatures to use StringView instead of @string.View for improved consistency and clarity
1 parent 2e3fb3d commit 2e882e3

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

string/regex/README.mbt.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ test {
2626
// Write a simple split with regexp
2727
fn split(
2828
regexp : @regex.Regex,
29-
target : @string.View,
30-
) -> Array[@string.View] {
29+
target : StringView,
30+
) -> Array[StringView] {
3131
let result = []
3232
for str = target {
3333
match regexp.execute(str) {
@@ -63,9 +63,9 @@ test {
6363

6464
### Inspect Results
6565

66-
- `result.content()``@string.View`
67-
- `result.before()``@string.View`
68-
- `result.after()``@string.View`
66+
- `result.content()``StringView`
67+
- `result.before()``StringView`
68+
- `result.after()``StringView`
6969
- `result.group(index)` → Capture group content
7070
- `result.named_group(name)` → Named capture group content
7171

string/regex/internal/regex_impl/chars.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ test "ordered range" {
8484

8585
///|
8686
/// TODO: consider unicode mode
87-
fn is_word_char_at(input : @string.View, sp : Int) -> Bool {
87+
fn is_word_char_at(input : StringView, sp : Int) -> Bool {
8888
if sp == -1 || sp == input.length() {
8989
return false
9090
}

string/regex/internal/regex_impl/impl.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ priv struct Thread {
5454
/// @param thread the current thread to add
5555
/// @param clist the list of threads to be processed in the next iteration
5656
fn add_thread(
57-
content : @string.View,
57+
content : StringView,
5858
instructions : Array[Instruction],
5959
inst_gen : Array[Int],
6060
thread : Thread,
@@ -136,7 +136,7 @@ fn add_thread(
136136
/// @return an array of integers representing the start and end indices of the matches, or an empty array if no match is found
137137
fn vm(
138138
instructions : Array[Instruction],
139-
input : @string.View,
139+
input : StringView,
140140
captures : Int,
141141
allow_exponentiaion? : Bool = false,
142142
) -> Array[Int] {

string/regex/internal/regex_impl/parse.mbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
7070
///|
7171
priv struct Parser {
72-
mut input : @string.View
72+
mut input : StringView
7373
mut flags : Flags
7474
mut captures : Int
7575
current_capture_scope : @set.Set[Int]
@@ -113,7 +113,7 @@ pub enum Err {
113113
///
114114
/// Contains error information and related string view context
115115
pub suberror RegexpError {
116-
RegexpError(err~ : Err, source_fragment~ : @string.View)
116+
RegexpError(err~ : Err, source_fragment~ : StringView)
117117
} derive(Show)
118118
119119
///|
@@ -123,7 +123,7 @@ pub suberror RegexpError {
123123
/// - `input`: String view of the regular expression to parse
124124
///
125125
/// Returns: New parser instance
126-
fn Parser::new(input : @string.View, flags : Flags) -> Parser {
126+
fn Parser::new(input : StringView, flags : Flags) -> Parser {
127127
Parser::{
128128
input,
129129
flags,
@@ -145,7 +145,7 @@ fn Parser::new(input : @string.View, flags : Flags) -> Parser {
145145
///
146146
/// Throws: Error_ when parsing fails
147147
fn parse(
148-
regex : @string.View,
148+
regex : StringView,
149149
flags? : Flags = Flags::default(),
150150
) -> ParseResult raise RegexpError {
151151
let parser = Parser::new(regex, flags)

string/regex/internal/regex_impl/top.mbt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
/// ))
3434
/// ```
3535
pub fn compile(
36-
regexp : @string.View,
37-
flags? : @string.View = "",
36+
regexp : StringView,
37+
flags? : StringView = "",
3838
) -> Regexp raise RegexpError {
3939
regexp
4040
|> parse(flags={
@@ -131,7 +131,7 @@ pub fn Regexp::group_names(self : Regexp) -> Array[String] {
131131
/// ))
132132
/// }
133133
/// ```
134-
pub fn Regexp::execute(self : Regexp, input : @string.View) -> MatchResult {
134+
pub fn Regexp::execute(self : Regexp, input : StringView) -> MatchResult {
135135
let captures = vm(self.instructions, input, self.capture)
136136
let (before, after) = if captures is [0..<_ as start, 0..<_ as end, ..] {
137137
(input.view(end_offset=start), input.view(start_offset=end))
@@ -154,7 +154,7 @@ pub fn Regexp::execute(self : Regexp, input : @string.View) -> MatchResult {
154154
///
155155
/// Returns: A tuple of
156156
/// - `MatchResult` object containing the match status and capture group information.
157-
/// - `@string.View` representing the remaining text after the match.
157+
/// - `StringView` representing the remaining text after the match.
158158
///
159159
/// Example:
160160
/// ```moonbit
@@ -171,8 +171,8 @@ pub fn Regexp::execute(self : Regexp, input : @string.View) -> MatchResult {
171171
#deprecated("Use `Regexp::execute` and `MatchResult::before`/`after` instead.")
172172
pub fn Regexp::execute_with_remainder(
173173
self : Regexp,
174-
input : @string.View,
175-
) -> (MatchResult, @string.View) {
174+
input : StringView,
175+
) -> (MatchResult, StringView) {
176176
let captures = vm(self.instructions, input, self.capture)
177177
if captures is [0..<_ as start, 0..<_ as end, ..] {
178178
(
@@ -220,7 +220,7 @@ pub fn Regexp::execute_with_remainder(
220220
/// inspect(result.after(), content=("xx"))
221221
/// assert_true(engine.match_("axxf") is None)
222222
/// ```
223-
pub fn Regexp::match_(self : Regexp, input : @string.View) -> MatchResult? {
223+
pub fn Regexp::match_(self : Regexp, input : StringView) -> MatchResult? {
224224
let captures = vm(self.instructions, input, self.capture)
225225
guard captures is [0..<_ as start, 0..<_ as end, ..] else { return None }
226226
let before = input.view(end_offset=start)
@@ -242,11 +242,11 @@ pub fn Regexp::match_(self : Regexp, input : @string.View) -> MatchResult? {
242242
/// - Index 4, 5: Start and end positions of the second capture group.
243243
/// - And so on...
244244
pub struct MatchResult {
245-
input : @string.View
245+
input : StringView
246246
captures : Array[Int]
247247
names : Map[String, Int]
248-
before : @string.View
249-
after : @string.View
248+
before : StringView
249+
after : StringView
250250
}
251251
252252
///|
@@ -294,7 +294,7 @@ pub fn MatchResult::matched(self : Self) -> Bool {
294294
/// #|Some("bc")
295295
/// ))
296296
/// ```
297-
pub fn MatchResult::get(self : Self, index : Int) -> @string.View? {
297+
pub fn MatchResult::get(self : Self, index : Int) -> StringView? {
298298
if self.captures.is_empty() ||
299299
index < 0 ||
300300
index >= self.captures.length() / 2 {
@@ -331,7 +331,7 @@ pub fn MatchResult::get(self : Self, index : Int) -> @string.View? {
331331
/// ))
332332
/// ```
333333
///
334-
pub fn MatchResult::groups(self : Self) -> Map[String, @string.View] {
334+
pub fn MatchResult::groups(self : Self) -> Map[String, StringView] {
335335
self.names
336336
.iter()
337337
.filter_map(p => if self.get(p.1) is Some(content) {
@@ -361,7 +361,7 @@ pub fn MatchResult::groups(self : Self) -> Map[String, @string.View] {
361361
/// #|[Some("abc"), Some("c")]
362362
/// ))
363363
/// ```
364-
pub fn MatchResult::results(self : Self) -> Array[@string.View?] {
364+
pub fn MatchResult::results(self : Self) -> Array[StringView?] {
365365
let results = []
366366
for i = 0; i < self.captures.length() / 2; i = i + 1 {
367367
let start = self.captures[i * 2]
@@ -387,7 +387,7 @@ pub fn MatchResult::results(self : Self) -> Array[@string.View?] {
387387
/// let result = engine.execute("say hello")
388388
/// inspect(result.before(), content="say hello")
389389
/// ```
390-
pub fn MatchResult::before(self : Self) -> @string.View {
390+
pub fn MatchResult::before(self : Self) -> StringView {
391391
self.before
392392
}
393393
@@ -403,7 +403,7 @@ pub fn MatchResult::before(self : Self) -> @string.View {
403403
/// let result = engine.execute("say yes")
404404
/// inspect(result.after(), content="")
405405
/// ```
406-
pub fn MatchResult::after(self : Self) -> @string.View {
406+
pub fn MatchResult::after(self : Self) -> StringView {
407407
self.after
408408
}
409409
@@ -455,7 +455,7 @@ test "rest method with capture groups" {
455455
///|
456456
test "rest method usage example" {
457457
let engine = compile("\\b\\w+\\b")
458-
let mut input : @string.View = "word1 word2 word3"
458+
let mut input : StringView = "word1 word2 word3"
459459
let (result1, rest1) = engine.execute_with_remainder(input)
460460
inspect(
461461
result1.get(0),

string/regex/regex.mbt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ struct MatchResult(@regex_impl.MatchResult)
1818

1919
///|
2020
#internal(experimental, "subject to breaking change without notice")
21-
pub fn MatchResult::before(self : Self) -> @string.View {
21+
pub fn MatchResult::before(self : Self) -> StringView {
2222
self.0.before()
2323
}
2424

2525
///|
2626
#internal(experimental, "subject to breaking change without notice")
27-
pub fn MatchResult::after(self : Self) -> @string.View {
27+
pub fn MatchResult::after(self : Self) -> StringView {
2828
self.0.after()
2929
}
3030

3131
///|
3232
#internal(experimental, "subject to breaking change without notice")
33-
pub fn MatchResult::content(self : Self) -> @string.View {
33+
pub fn MatchResult::content(self : Self) -> StringView {
3434
self.0.get(0).unwrap()
3535
}
3636

3737
///|
3838
#internal(experimental, "subject to breaking change without notice")
39-
pub fn MatchResult::group(self : Self, index : Int) -> @string.View? {
39+
pub fn MatchResult::group(self : Self, index : Int) -> StringView? {
4040
self.0.get(index)
4141
}
4242

4343
///|
4444
#internal(experimental, "subject to breaking change without notice")
45-
pub fn MatchResult::named_group(self : Self, name : String) -> @string.View? {
45+
pub fn MatchResult::named_group(self : Self, name : String) -> StringView? {
4646
guard self.0.names.get(name) is Some(index) else { None }
4747
self.0.get(index)
4848
}
@@ -53,13 +53,13 @@ struct Regex(@regex_impl.Regexp)
5353

5454
///|
5555
#internal(experimental, "subject to breaking change without notice")
56-
pub fn compile(pattern : @string.View) -> Regex raise {
56+
pub fn compile(pattern : StringView) -> Regex raise {
5757
@regex_impl.compile(pattern)
5858
}
5959

6060
///|
6161
#internal(experimental, "subject to breaking change without notice")
62-
pub fn Regex::execute(self : Self, input : @string.View) -> MatchResult? {
62+
pub fn Regex::execute(self : Self, input : StringView) -> MatchResult? {
6363
match self.0.match_(input) {
6464
None => None
6565
Some(result) => Some(MatchResult(result))

0 commit comments

Comments
 (0)