Skip to content

Commit 3aa860e

Browse files
committed
Add protocol TokenCounter
1 parent 8efcd70 commit 3aa860e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
public struct CharacterTokenCounter: TokenCounter {
4+
public func countToken(text: String) -> Int {
5+
text.count
6+
}
7+
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import Foundation
22

3-
public protocol TokenEncoder {
3+
public protocol TokenEncoder: TokenCounter {
44
func encode(text: String) -> [Int]
55
}
66

7-
public extension TokenEncoder {
7+
extension TokenEncoder {
88
func countToken(text: String) -> Int {
99
encode(text: text).count
1010
}
1111
}
12+
13+
public protocol TokenCounter {
14+
func countToken(text: String) -> Int
15+
}

0 commit comments

Comments
 (0)