Skip to content

Commit a803601

Browse files
committed
Renamed to AsRuneSlice and included more doc
1 parent 1c140a0 commit a803601

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

stringbuilder.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,25 @@ func (s *StringBuilder) RuneAt(index int) rune {
116116
return s.data[index]
117117
}
118118

119-
// Returns the string builder as a rune-slice
120-
func (s *StringBuilder) AsRune() []rune {
119+
// Returns the string builder as a rune-slice. Be careful as this returns the internal slice.
120+
// Changes to that will reflect in this string builder instance.
121+
func (s *StringBuilder) AsRuneSlice() []rune {
121122
return s.data[:s.position]
122123
}
123124

124125
// Returns the first occurrence of the given text in the string builder. Returns -1 if not found
125126
func (s *StringBuilder) FindFirst(text string) int {
126-
return findFirst(s.AsRune(), text)
127+
return findFirst(s.AsRuneSlice(), text)
127128
}
128129

129130
// Returns the last occurrence of the given text in the string builder. Returns -1 if not found
130131
func (s *StringBuilder) FindLast(text string) int {
131-
return findLast(s.AsRune(), text)
132+
return findLast(s.AsRuneSlice(), text)
132133
}
133134

134135
// Returns all occurrences of the given text in the string builder. Returns an empty if no occurrence found.
135136
func (s *StringBuilder) FindAll(text string) []int {
136-
return findAll(s.AsRune(), text)
137+
return findAll(s.AsRuneSlice(), text)
137138
}
138139

139140
func (s *StringBuilder) grow(lenToAdd int) {

stringbuilder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func TestAsRune(t *testing.T) {
175175
expected := []rune{'H', 'e', 'l', 'l', 'o'}
176176
sb := NewStringBuilderFromString("Hello")
177177

178-
if result := sb.AsRune(); !reflect.DeepEqual(result, expected) {
178+
if result := sb.AsRuneSlice(); !reflect.DeepEqual(result, expected) {
179179
t.Errorf("Actual %q, Expected: %q", result, expected)
180180
}
181181
}

0 commit comments

Comments
 (0)