View Issue Details

IDProjectCategoryView StatusLast Update
0005463JEDI VCL00 JVCL Componentspublic2011-09-21 14:10
ReportermburyAssigned ToAHUser 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version3.45 
Summary0005463: SubStrBySeparator function doesn't work with 'empty' substring
DescriptionSubStrBySeparator function does not return 'empty' substring when two 1-character separators are placed one by one.
Sample string is: EQD+CN++2200+++4. Separator is '+'. When I want to get third substring I call SubStrBySeparator('EQD+CN++2200+++4', 2, '+'). It should return empty string but it returns +2200.
The reason of such result is following line:
 I := PosIdx(Separator, S, StartIndex + 1);
while StartIndex was increased earlier in the 'for' loop by:
 Inc(StartIndex, LenSeparator);

When I change it to:
 I := PosIdx(Separator, S, StartIndex);

everything works great I get empty substrings where I expect to get.


Additional InformationIt should not take too much time to correct this, right?
TagsNo tags attached.

Activities

obones

2011-02-15 13:50

administrator   ~0018354

Changing the behavior of the function is not desirable, some people might rely on it.
It would be better to add a parameter (AllowEmpty for instance) that controls the activation of new behavior (and that is off by default)
Can you try to do this?

mbury

2011-04-15 10:42

reporter   ~0018520

Sure, I can try adding the AllowEmpty parameters defaulted to False, and modify "I" variable accordingly. That is not a problem.
But I cannot understand what is the purpose relying on behavior that instead of empty string next item is returned, and with separator.
The point is that the result of the function should be correct. In my opinion the correct result of this function when it happens that two separators are placed one by one is empty string.

obones

2011-06-08 16:31

administrator   ~0018694

I'm not saying anyone relies on this, but if we change it and that breaks their code, they're gonna blame us.
So if you could submit a patch with the changes, that would make inclusion easier
Thanks

AHUser

2011-06-11 12:05

developer   ~0018737

Fixed in svn revision 13060.

@obones: This code was definitely wrong. And I doubt that anybody would have expected the function to return '+2200' for Index=2 and '2200' for Index=3.

Issue History

Date Modified Username Field Change
2011-01-19 15:27 mbury New Issue
2011-02-15 13:50 obones Note Added: 0018354
2011-02-15 13:50 obones Status new => feedback
2011-04-15 10:42 mbury Note Added: 0018520
2011-06-08 13:27 obones Status feedback => acknowledged
2011-06-08 16:31 obones Note Added: 0018694
2011-06-11 11:33 AHUser Assigned To => AHUser
2011-06-11 12:05 AHUser Note Added: 0018737
2011-06-11 12:05 AHUser Status acknowledged => resolved
2011-06-11 12:05 AHUser Fixed in Version => Daily / SVN
2011-06-11 12:05 AHUser Resolution open => fixed
2011-09-21 14:10 obones Fixed in Version Daily / SVN => 3.45