Skip to content

Commit 600800a

Browse files
authored
TibiaCharactersCharacter: remove title regex (tibiadata#223)
1 parent 7a0c248 commit 600800a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/TibiaCharactersCharacter.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ const Br = 0x202
124124

125125
var (
126126
summonRegex = regexp.MustCompile(`(an? .+) of ([^<]+)`)
127-
titleRegex = regexp.MustCompile(`(.*) \(([0-9]+).*`)
128127
characterInfoRegex = regexp.MustCompile(`<td.*<nobr>[0-9]+\..(.*)<\/nobr><\/td><td.*><nobr>(.*)<\/nobr><\/td><td style="width: 70%">(.*)<\/td><td.*`)
129128
)
130129

@@ -197,9 +196,24 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (*CharacterResponse, er
197196
case "Sex:":
198197
CharacterInfoData.Sex = RowData
199198
case "Title:":
200-
subma1t := titleRegex.FindAllStringSubmatch(RowData, -1)
201-
CharacterInfoData.Title = subma1t[0][1]
202-
CharacterInfoData.UnlockedTitles = TibiaDataStringToInteger(subma1t[0][2])
199+
leftParenIdx := strings.Index(RowData, "(")
200+
if leftParenIdx == -1 {
201+
return
202+
}
203+
204+
title := RowData[:leftParenIdx-1]
205+
206+
spaceIdx := strings.Index(RowData[leftParenIdx:], " ")
207+
if spaceIdx == -1 {
208+
return
209+
}
210+
211+
unlockedTitles := TibiaDataStringToInteger(
212+
RowData[leftParenIdx+1 : leftParenIdx+spaceIdx],
213+
)
214+
215+
CharacterInfoData.Title = title
216+
CharacterInfoData.UnlockedTitles = unlockedTitles
203217
case "Vocation:":
204218
CharacterInfoData.Vocation = RowData
205219
case "Level:":

0 commit comments

Comments
 (0)