HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Adv. String Function - Help Needed

03-14-2004, 11:10 PM#1
PEON1577
I'm trying to make a function that picks up a word with an optional
offset in a string. if the offset is zero then the function will just
search for the word but if the offset is a number, lets say one, then
it should search for that word with the offset one. lets look at an
example:

string: this is a test
word: test
offset: 1

if the following words are present in string then they should return
the value found because of the offset being one, the character x is
used to represent any possible single character:
test
txest
texst
tesxt
xest
txst
text
tesx

My function is able to pick up almost all of the above but it has
problems with things like texst because no matter where i put the word
test under it three characters will not line up. Please tell me how to
modify my code to make it work correctly.

Code:
function filter takes string source, string word, integer offset
returns string
local integer loop_source = 1
local integer loop_word = 1
local integer match = 0
 
loop
exitwhen (loop_source > StringLength(source))

if (SubStringBJ(source, loop_source, loop_source) == SubStringBJ(word,
loop_word, loop_word)) then
set match = match + 1
set loop_source = loop_source + 1
set loop_word = loop_word + 1
 if (match >= StringLength(word) - offset) then
 return "found"
 endif
else
set loop_source = loop_source + 1
set loop_word = loop_word + 1
endif

if (loop_word  >= StringLength(word) ) then
set loop_source = ((loop_source + 1) - StringLength(word))
set loop_word = 1
set match = 0
endif

endloop

return "not_found"

endfunction
03-15-2004, 09:36 AM#2
jmoritz
Code:
if (SubStringBJ(source, loop_source, loop_source) == SubStringBJ(word,
loop_word, loop_word)) then
set match = match + 1
set loop_source = loop_source + 1
set loop_word = loop_word + 1
 if (match >= StringLength(word) - offset) then
 return "found"
 endif
else
set loop_source = loop_source + 1
set loop_word = loop_word + 1   <--- remove this I think
endif

When it tries to match an x in texst, it can't, and then you increase loop_word, which means the next character in word (test) will be t, instead of s.
03-15-2004, 10:57 AM#3
PEON1577
Code:
if (SubStringBJ(source, loop_source, loop_source) == SubStringBJ(word,
loop_word, loop_word)) then
set match = match + 1
set loop_source = loop_source + 1
set loop_word = loop_word + 1
 if (match >= StringLength(word) - offset) then
 return "found"
 endif
else
set loop_source = loop_source + 1
set loop_word = loop_word + 1   <--- remove this I think
endif


ok not incrimenting loop_word when a match is not made enabled the function to pick up texst but now it cant pick up xest or txst.

any more ideas?

remember it should be able to pick up the following bc of the offset being one:
test
txest
texst
tesxt
xest
txst
text
tesx
03-16-2004, 07:44 PM#4
PEON1577
^_^

nyone?
03-17-2004, 02:35 PM#5
jmoritz
matching texst and txst are 2 very different things. In the first case, you shouldn't increase word_loop, but in the second, you should. This is getting more complex than writing a regular expression engine in JASS if you're not careful. Maybe you should reconsider what you are really trying to achieve here. Why do you need this function in a war3 map?
03-18-2004, 11:04 PM#6
PEON1577
Quote:
Originally Posted by jmoritz
matching texst and txst are 2 very different things. In the first case, you shouldn't increase word_loop, but in the second, you should. This is getting more complex than writing a regular expression engine in JASS if you're not careful. Maybe you should reconsider what you are really trying to achieve here. Why do you need this function in a war3 map?

When you can't do something you try and tell your self that since it has no reasonable application then it doesn't matter that you can't do it. The functions application shouldn't matter in this case. I've stated my objective and I am asking for help not asking for people to tell me that it's pointless. God forbid someone learns something trying a new function.

AFAIK what I'm trying to do is possible, I've attempted to do it yet I'm missing something. Either it can't be done (it should be doable) or my function needs to be changed a lot to make it work. I was hoping you people would be able to point out what's wrong with my function or how to expand upon it to complete my goal but instead I get one attempt where the person didn't even TRY the outputs (me running the function and you running it are not two diff things, it either works or it doesn't) then I have this wonderful post saying well I'm really to lazy to even try solving it and since it doesn't do anything then that's OK.

Maybe you have another reason for posting that's somehow indirectly related to your question of if it does something. I have considered what I am trying to achieve and why it's necessary in the WC3 map, I am asking for help with the function.

People ask for help in math to get something to work and often its not the end result that useful, say a formula, its what you _do_ with it. I fail to see why you want to change the subject/avoid talking about ways to make a function do what I want instead of trying to help me solve my problem.

If there is no one here who can help me then I will continue to work on it alone, shame on me for thinking other intelligent life exists on forums.
03-19-2004, 10:23 AM#7
Cubasis
Did you read jmoritz post except his last part?

I imagine you're trying to do this for some anti-bad-language system or sumtin. However, as jmoritz said, sensing shiit and $hit are 2 VERY different things, so sensing them requires two different systems. Thus making this function much performance-heavyer than one would want. That's what I imagine bothers jmoritz, as coders prefer to make smart code than sequential, heavy code...and for this instance there is no way to do it smartly, instead one needs to make two types of checks, and run them in order.

And if you didn't know, "Regular Expressions" are advanced searching (matching) system that has syntax to allow you to search for most anything. The syntax is something like this: "[a-zA-Z0-9_]*" That's why he was asking you to reconsider what you're trying to achieve as, if applicable to your needs, then a Regular Expression function could be better than this.

But that's your sollution...to do the two different checks in a row.

Good luck.
Cubasis
03-21-2004, 03:03 AM#8
PEON1577
Quote:
Originally Posted by Cubasis40
Did you read jmoritz post except his last part?

I imagine you're trying to do this for some anti-bad-language system or sumtin. However, as jmoritz said, sensing shiit and $hit are 2 VERY different things, so sensing them requires two different systems. Thus making this function much performance-heavyer than one would want. That's what I imagine bothers jmoritz, as coders prefer to make smart code than sequential, heavy code...and for this instance there is no way to do it smartly, instead one needs to make two types of checks, and run them in order.

And if you didn't know, "Regular Expressions" are advanced searching (matching) system that has syntax to allow you to search for most anything. The syntax is something like this: "[a-zA-Z0-9_]*" That's why he was asking you to reconsider what you're trying to achieve as, if applicable to your needs, then a Regular Expression function could be better than this.

But that's your sollution...to do the two different checks in a row.

Good luck.
Cubasis

I know that once the trigger is complete it will not be able to be used do to the amount of lag it would generate but I would like to know how to complete my function anyway. I have tryed adding an additional check and it did not seem to work. I will post my updated code.
Code:
function filter takes string source, string word, integer offset returns string
local integer loop_source = 1
local integer loop_word = 1
local integer match = 0

loop
exitwhen (loop_source > StringLength(source))
if (SubStringBJ(source, loop_source, loop_source) == SubStringBJ(word, loop_word, loop_word)) then
set match = match + 1
set loop_source = loop_source + 1
set loop_word = loop_word + 1
 if (match >= StringLength(word) - offset) then
 return "found1"
 endif
else
set loop_source = loop_source + 1
set loop_word = loop_word + 1
endif
if (loop_word  >= StringLength(word) ) then
set loop_source = ((loop_source + 2) - StringLength(word))
set loop_word = 1
set match = 0
endif
endloop

set loop_source = 1
set loop_word = 1
set match = 0

loop
exitwhen (loop_source > StringLength(source))
if (SubStringBJ(source, loop_source, loop_source) == SubStringBJ(word, loop_word, loop_word)) then
set match = match + 1
set loop_source = loop_source + 1
set loop_word = loop_word + 1
 if (match >= StringLength(word) - offset) then
 return "found2"
 endif
else
set loop_source = loop_source + 1
set loop_word = loop_word + 1
endif
if (loop_word  >= StringLength(word) ) then
set loop_source = ((loop_source + 2) - StringLength(word))
//set loop_word = 1
set match = 0
endif
endloop

return "not_found"

endfunction

Now please tell me how to edit my function to make it do as I wish.

Quote:
And if you didn't know, "Regular Expressions" are advanced searching (matching) system that has syntax to allow you to search for most anything. The syntax is something like this: "[a-zA-Z0-9_]*" That's why he was asking you to reconsider what you're trying to achieve as, if applicable to your needs, then a Regular Expression function could be better than this.
as long as its in JASS and it does what i've previosly stated then i'm all for it, I just want to get a function to do what i've stated in jass. See my 1st post for what the function should be able to do. Also note that the code I am posting is merly my attempt at making the function do what I want, I'm asking for ways on how to fix the function to do what I want b/c it is _not_ currently working correctly - so if this means rewriting the entire function then so beit, but keep it in JASS. I know its much simpler to do in a higher level language.
03-22-2004, 08:12 PM#9
PEON1577
yay all that and no one knows how to fix it..
03-24-2004, 02:00 AM#10
PEON1577
:gruntsad4: ny smrt ppl out there?
03-24-2004, 02:37 AM#11
AIAndy
Stop bumping your own thread so often.

I'd change the structure of your code to split it up into 2 functions, one that tries to match the word from a certain position on and one that applies the former function on all positions.
And in the second case in your function you need to not increase word_loop when there is no match and you need a different condition when you are finished.
03-24-2004, 09:30 AM#12
jmoritz
What you are asking is for us to write a function that does exactly what you want, without telling us why you need it. It doesn't work that way. Either you tell us why you need it, or be content with the help that is offered at the moment. The other reason I was asking why you need it, is because there might be a different, easier solution to your problem.

As for a quick fix for the function: you simply create 2 functions, 1 for replacement chars (increase word_loop), and 1 for additional chars (not increase word_loop), then call both of them in a third function. This will not match string where characters have been replaced, and added (a combination of the two, f.ex. "txsxt"). If you want that as well, you need a more serious backtracking system.
03-30-2004, 04:09 AM#13
PEON1577
Quote:
Originally Posted by wc3jass3
I don't have much time but I have quickly read over the comments and I am posting this quick reply.

Quote:
Originally Posted by quick reply
If the function is completed it will be for finding a string inside a string.

Quote:
Originally Posted by jmoritz
What you are asking is for us to write a function that does exactly what you want, without telling us why you need it.
I don't "need" this function, I am trying to do it because its difficult.

If you refuse to work on JASS that is difficult for the sake of a challenge then stop posting in this thread!

I have done some more work on the function which I will post later.
☼☼☼☼☼☼☼☼☼☼
04-02-2004, 12:39 AM#14
PEON1577
Ok here are the revised questions:

Given a string Word and an offset O write a function to list all variations of Word including Word.

My definition of offset could be different from yours so you will have to use this example to understand what I am calling offset.
If Word = test and O = 0 then the function would return test
If Word = test and O = 1 then the function would return
test
xest
txst
text
tesx
txest
texst
tesxt
where x represents a single character (bc O=1)
If Word = test and O = 2 then the function would return
test
xest
txst
text
tesx
txest
texst
tesxt
where x represents a single character or two characters (bc O=2)

I'm very intrested in seeing a function that can do this, right now I have only gotten it to work for specific cases and havent been able to generalize it out. There are some smart people here so it would be nice if one of them would show me how this function is done. Thanks for your time!
04-03-2004, 01:10 AM#15
PEON1577
Quote:
Originally Posted by AIAndy
Stop bumping your own thread so often.

I'd change the structure of your code to split it up into 2 functions, one that tries to match the word from a certain position on and one that applies the former function on all positions.
And in the second case in your function you need to not increase word_loop when there is no match and you need a different condition when you are finished.

I'm not bumping it that often, anyway *bump*

If i bump the thread it gets looked at.

Please look at my new revised question and see if you can help me.

Thank you! :D