Добавлен Doc,
опубликован
Алгоритмы, Наработки и Способности
Способ реализации:
cJass
Тип:
Наработка
struct String{
private string Main
private string cache
public int length
static String create(string Main){
String data = String.allocate()
data.Main = Main
data.cache = Main
data.length = StringLength(Main)
return data
}
String clone(){
return String.create(Main)
}
void val(string s){
this.Main = s
this.length = StringLength(Main)
}
string get(){
return this.Main
}
bool equalsStr(string s){
return (s == Main)
}
bool equals(String s){
return (s.get() == Main)
}
void updateCache(){
this.cache = this.Main
}
void removeAll(string s){
int i = 0
int e = this.length
int ls = StringLength(s)
whilenot(i == e){
if (SubString(this.Main, i, i + ls) == s){
this.Main = SubString(this.Main, 0, i) + SubString(this.Main, i + ls, e)
e = StringLength(this.Main)
i--
}
i++
}
this.length = StringLength(Main)
}
int firstAfter(int b, string s){
int i = b, j = 0
int e = this.length
int ls = s.length
whilenot(i == e){
if (SubString(this.Main, i, i + ls) == s){
return i
}
i++
}
return -1
}
int countOf(string s){
int i = 0, j = 0
int e = this.length
int ls = StringLength(s)
whilenot(i == e){
if (SubString(this.Main, i, i + ls) == s){
j++
}
i++
}
return j
}
int indexOf(string s, int num){
int i = 0, j = 0
int e = this.length
int ls = StringLength(s)
int index[]
whilenot(i == e){
if (SubString(this.Main, i, i + ls) == s){
index[j] = i
j++
}
i++
}
if (num > j){
num = j
}
return index[num]
}
int indexOfEnd(string s, int num){
int i = 0, j = 0
int e = this.length
int ls = StringLength(s)
int index[]
whilenot(i == e){
if (SubString(this.Main, i, i + ls) == s){
index[j] = i + ls
j++
}
i++
}
if (num > j){
num = j
}
return index[num]
}
int getInt(int num){
int i, j = 0, k
int c = this.length
int ints[]
ints[0] = 0
whilenot (c < 0){
i = 0
whilenot (i > c){
k = S2I(SubString(this.Main, i - 1, c))
if (k != 0){
ints[j] = k
j++
}
i++
}
c--
}
if (num > j){
num = j
}
return ints[num]
}
void substr(int index, int length){
this.Main = SubString(this.Main, index, index + length)
this.length = StringLength(Main)
}
bool contains(string s){
int i = 0
int e = this.length
int ls = StringLength(s)
whilenot(i == e){
if (SubString(this.Main, i, i + ls) == s){
return true
}
i++
}
return false
}
void reset(){
this.val(this.cache)
}
void destroy(){
this.Main = null
this.length = 0
this.deallocate()
}
}
Пример использования:
String s = String.create(in) // создаем строку
s.removeAll("-") // удаляем все символы "-" и " "
s.removeAll(" ")
s.updateCache() // записываем в кеш строки ее текущую версию
for(int i = 0; i < s.length; i += 2){
s.substr(i, 2) // выбираем подстроку от i до i + 2
if (s.equalsStr("ns")){ // если подстрока равна "ns" - устанавливаем нужный мод
Mode.modeNormalShield = true
} elseif (s.equalsStr("ni")){
Mode.modeNoItems = true
} elseif (s.equalsStr("tp")){
Mode.modeTeamPlay = true
} else { // если мод не валиден - уничтожаем объект строки, завершаем выполнение
s.destroy()
return ""
}
s.reset() // возвращаем значение строки к той, что находится в кеше
}
s.destroy() // обязательно уничтожаем объект в конце выполнения
`
ОЖИДАНИЕ РЕКЛАМЫ...
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
Master_chan, а то.