|
library JASSLANG
struct String
string S = null
//! define char string
method FindFirst takes integer index, string text returns integer
local integer n = StringLength(this.S)
local integer m = StringLength(text)
local integer i = 0
local integer j = 0
local integer t = 0
local char array src
local char array tgt
if m > n or index > n then
return -1
endif
loop
exitwhen i >= n
set src = SubString(this.S,i,i+1)
set i = i + 1
endloop
loop
exitwhen j >= m
set tgt[j] = SubString(text,j,j+1)
set j = j + 1
endloop
set i = index - 1
set j = 0
loop
exitwhen i >= n
set t = i
set j = 0
loop
if j >= m then
return t + 1
endif
exitwhen tgt[j] != src
set j = j + 1
set i = i + 1
endloop
set i = t + 1
endloop
return 0
endmethod
endstruct
endlibrary |
|