Skip to content

Commit 1ca6b64

Browse files
committed
Added rune methods
1 parent b282927 commit 1ca6b64

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
66

77
## [Unreleased]
88

9+
### Added
10+
- Added the following methods: `RuneAt`, `AsRune`
11+
912
## [0.2.0] - 2022-12-23
1013

1114
### Added

search.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package Text
2+
3+
var arrayEmpty = make([]int, 0)
4+
5+
func findAllText(text []rune, needle string) []int {
6+
if len(text) == 0 || len(needle) == 0 || len(text) < len(needle) {
7+
return arrayEmpty
8+
}
9+
10+
return arrayEmpty
11+
}

stringbuilder.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ func (s *StringBuilder) Clear() {
111111
s.position = 0
112112
}
113113

114+
// Gets the rune at the specific position
115+
func (s *StringBuilder) RuneAt(index int) rune {
116+
return s.data[index]
117+
}
118+
119+
// Returns the string builder as a rune-slice
120+
func (s *StringBuilder) AsRune() []rune {
121+
return s.data[:s.position]
122+
}
123+
124+
// Replaces all occurences of a given string with a new one
125+
func (s *StringBuilder) replace(original string, new string) {
126+
occurences := findAllText(s.AsRune(), original)
127+
128+
for _, _ = range occurences {
129+
130+
}
131+
}
132+
114133
func (s *StringBuilder) grow(lenToAdd int) {
115134
// Grow times 2 until lenToAdd fits
116135
newLen := cap(s.data)

stringbuilder_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package Text
22

33
import (
4+
"reflect"
45
"testing"
56
)
67

@@ -161,3 +162,20 @@ func TestClear(t *testing.T) {
161162
t.Errorf("Expected empty string but did receive %v", result)
162163
}
163164
}
165+
166+
func TestRuneAt(t *testing.T) {
167+
sb := NewStringBuilderFromString("Hello")
168+
169+
if result := sb.RuneAt(1); result != 'e' {
170+
t.Errorf("Actual %q, Expected: %q", result, 'e')
171+
}
172+
}
173+
174+
func TestAsRune(t *testing.T) {
175+
expected := []rune{'H', 'e', 'l', 'l', 'o'}
176+
sb := NewStringBuilderFromString("Hello")
177+
178+
if result := sb.AsRune(); !reflect.DeepEqual(result, expected) {
179+
t.Errorf("Actual %q, Expected: %q", result, expected)
180+
}
181+
}

0 commit comments

Comments
 (0)