Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Wrong spell checker on russian (and probably other languages)

<< < (9/10) > >>

oBFusCATed:
You'll do 3 iterations of the loop each time moving by 1.

The same would happen with the current version, I think. In fact I think your version is probably wrong if posToAdd is larger than one. On the first iteration it will move by one character, on the second it will move by two, possibly skipping one characters. But I guess WordStartPosition is hiding it, because it can go back. Can it? Or are you saying that WordStartPosition would return the position at the start of the whole sequence of EOL chars no matter where in the sequence pos is?

BlueHazzard:

--- Quote --- WordStartPosition would return the position at the start of the whole sequence of EOL chars no matter where in the sequence pos is?
--- End quote ---
Wordstart AND wordend can go before pos. Exactly That is the problem... And my code can jump past this problem.
[Edit:] This probably can be mitigated (i have not checked id, and can probably lead to other problems)  , by using pos for the findWordEnd function. (but some where more up this topic you suggested to use wordStart to find wordEnd and not pos)

oBFusCATed:
So you'll get a situation where wordend<pos isn't it? Then why don't you just increment pos with one in this case and do another iteration of the loop?

BlueHazzard:
Ok, let me try to explain:

we have the string "\r\n\n"


--- Code: ---1)
// first loop
pos==0; // str[pos] == '\r'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
pos = wordend; //== 0
2) // Second loop: pos++
pos==1; // str[pos] == '\n'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
pos = wordend;//  == 0
3) // Third loop: pos++
pos==1; // str[pos] == '\n'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
pos = wordend;//  == 0

--- End code ---
this does not work...


--- Code: ---1)
// first loop
pos==0; // str[pos] == '\r'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
if(pos == wordend ) pos++;// == 1

2) // Second loop: pos++
pos==2; // str[pos] == '\n'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
if(pos == wordend ) pos++;// == 1
3) // Third loop: pos++
pos==2; // str[pos] == '\n'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
if(pos == wordend ) pos++;// == 1

--- End code ---
this also does not work

my code:


--- Code: ---0)
oldpos=0;
incstep=0;
1)
// first loop
pos==0; // str[pos] == '\r'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
pos = worend;
if(pos == oldpos)
{
   incstep++;// == 1
   pos+=incstep;// == 1
}
2) // Second loop: pos++
pos==2; // str[pos] == '\n'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
pos = worend;
if(pos == oldpos)
{
   incstep++;// == 2
   pos+=incstep;// == 2
}
3) // Third loop: pos++
pos==3; // str[pos] == 'X' // <------ YAYYYYY PAST THE 2
....

--- End code ---

My code works also for "\r\n\n\n\n\n\n\n\n\n\n\n\n\n" without any special ifs...

oBFusCATed:

--- Quote from: BlueHazzard on November 12, 2019, 11:07:37 pm ---Ok, let me try to explain:

we have the string "\r\n\n"


--- Code: ---1)
// first loop
pos==0; // str[pos] == '\r'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
pos = wordend; //== 0
2) // Second loop: pos++
pos==1; // str[pos] == '\n'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
pos = wordend;//  == 0
3) // Third loop: pos++
pos==1; // str[pos] == '\n'
wordstart  = findwordstart(pos);// == 0;
wordend = findwordend(wordstart);// == 0;
pos = wordend;//  == 0

--- End code ---

--- End quote ---

Why is pos==1 at iteration 3? If you add a condition if (wordend<pos) pos++; then at iteration 2 pos would be incremented to 2 and everything would be good and working. Am I still missing something?

You should of course make line pos = wordend; to be conditional...Something like:

--- Code: ---if (wordend > pos)
  pos = wordend;
else
  pos++;

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version