All,
I have a generic question about using the APT_STRING class as part of creating a custom operator. I have an instance in my source where I have created an APT_STRING object and populated it with a string. If I attempt to make the string smaller I always receive a compiler error complaining about the span of the object. Has anyone else experienced this? Am I doing this wrong? I'm using Information Server 8.5.
Example:
APT_STRING myAPTString = "MC Daniel";
myAPTString = "ABC";
error message:
##F IIS-DSEE-TFSF-00005 11:50:12(008) <lssimix,0> Fatal Error: When replacing a substring, offset+span is too large: offset: 3; span: 1
str
Custom Operators (APT_STRING)
Moderators: chulett, rschirm, roy
Custom Operators (APT_STRING)
William Black
Re: Custom Operators (APT_STRING)
Are you using the substring or replace functions of the APT_STRING class in your operator? If so, the error is indicating that you are attempting to access a substring that extends past the end of your current string.
APT_STRING string;
string = "ABC";
Using offset 3, span 1 with "ABC" would trigger the error because offset 3 is beyond the end of "ABC". Offset 2, span 1 would return "C". "C" is at offset 2 (the third character of the string). Offsets start numbering with 0, bytes/positions start with 1.
If you are receiving the error with only the logic you show in your post, I would suggest contacting your official support provider.
Regards,
APT_STRING string;
string = "ABC";
Using offset 3, span 1 with "ABC" would trigger the error because offset 3 is beyond the end of "ABC". Offset 2, span 1 would return "C". "C" is at offset 2 (the third character of the string). Offsets start numbering with 0, bytes/positions start with 1.
If you are receiving the error with only the logic you show in your post, I would suggest contacting your official support provider.
Regards,
- james wiles
All generalizations are false, including this one - Mark Twain.
All generalizations are false, including this one - Mark Twain.
Re: Custom Operators (APT_STRING)
No, I simply have an APT_STRING object that is a certain length and when I attempt to make it shorter it complains with this error. I noticed that if I make the string longer it's find but if you ever attempt to make it smaller it complains. I use the assignment operator '=' which is overrode.
jwiles wrote:Are you using the substring or replace functions of the APT_STRING class in your operator? If so, the error is indicating that you are attempting to access a substring that extends past the end of your current string.
APT_STRING string;
string = "ABC";
Using offset 3, span 1 with "ABC" would trigger the error because offset 3 is beyond the end of "ABC". Offset 2, span 1 would return "C". "C" is at offset 2 (the third character of the string). Offsets start numbering with 0, bytes/positions start with 1.
If you are receiving the error with only the logic you show in your post, I would suggest contacting your official support provider.
Regards,
William Black
Re: Custom Operators (APT_STRING)
I tested the following logic in an 8.1FP1 environment on RedHat and did not have any problem.
However, I did recreate the error when I added this line after the above:
##F IIS-DSEE-TFSF-00005 17:58:36(005) <describeoutput,0> Fatal Error: When replacing a substring, offset+span is too large: offset: 3; span: 1
This points to something in your logic attempting to replace part of the string. If that's not the case, contact your support provider.
Regards,
Code: Select all
APT_String mystring = "MC Daniel";
mystring = "ABC";
Code: Select all
mystring.replace(3,1,"Z");
This points to something in your logic attempting to replace part of the string. If that's not the case, contact your support provider.
Regards,
- james wiles
All generalizations are false, including this one - Mark Twain.
All generalizations are false, including this one - Mark Twain.
Thanks for your continued feedback. Yes, I'm trying to replace a portion of the string. Basically I'm attempting to remove the space from the string ('Mc Daniel' -> 'McDaniel'). I start by coping the APT_String into a C-style buffer. Once this is done I shift the data over removing the space. Lastly, I attempt to copy the manipulated string back to an APT_String. I tried copying it directly back to the original APT_String but it complained with the mentioned 'span' error message. In addition, I attempted to create a new APT_String and them copy it back to the original APT_String. In both cases mentioned the same error appears. It has an issue with making the APT_String smaller.
APT_STRING myAPTString = "Mc Daniel";
char buffer[256];
char buffer2[256];
strcpy(buffer,myString);
strncpy(buffer2,buffer,match_found); //match_found is the index location of the space
strncpy(&buffer2[match_found],&buffer[match_found+1],(myString.length()-match_found+1));
buffer2[(myString.length()-match_found+1)] = '\0';
APT_String myTempAPTString(buffer2,strlen(buffer2));
myAPTString = myTempAPTString;
error message:
##F IIS-DSEE-TFSF-00005 11:50:12(008) <lssimix,0> Fatal Error: When replacing a substring, offset+span is too large: offset: 3; span: 1
APT_STRING myAPTString = "Mc Daniel";
char buffer[256];
char buffer2[256];
strcpy(buffer,myString);
strncpy(buffer2,buffer,match_found); //match_found is the index location of the space
strncpy(&buffer2[match_found],&buffer[match_found+1],(myString.length()-match_found+1));
buffer2[(myString.length()-match_found+1)] = '\0';
APT_String myTempAPTString(buffer2,strlen(buffer2));
myAPTString = myTempAPTString;
error message:
##F IIS-DSEE-TFSF-00005 11:50:12(008) <lssimix,0> Fatal Error: When replacing a substring, offset+span is too large: offset: 3; span: 1
William Black
How about trying this instead:
mystring.removePadding(' ');
The APT_String class has many built-in functions. You can look at the basicstring.h include file under:
$DSHOME/../PXEngine/include/apt_util
which will list all of the functionality available to the underlying basicstring class upon which APT_String is build.
Regards,
mystring.removePadding(' ');
The APT_String class has many built-in functions. You can look at the basicstring.h include file under:
$DSHOME/../PXEngine/include/apt_util
which will list all of the functionality available to the underlying basicstring class upon which APT_String is build.
Regards,
- james wiles
All generalizations are false, including this one - Mark Twain.
All generalizations are false, including this one - Mark Twain.
In reference to your C logic above:
Keep in mind that the APT_String C++ class is NOT the same as the C++ std::string class. The member functions are not the same, nor are operators overloaded in necessarily the same way.
I imagine that your buffer and buffer2 character arrays didn't contain the quite data you were expecting, or that the overloaded ops weren't working in the way you imagined, and that one or the other lead to the error.
A straightforward bit of logic, using the built-in member functions of APT_String, could be:
This allows you to selectively replace the spaces. You could put this into a loop if needed. removePadding() would remove ALL occurrences of the given pad character (space is the default).
To stick with a C implementation such as your logic, I think the following would be safer:
The former would be the preferred method, allowing the class to perform the heavy lifting for you.
Regards,
Keep in mind that the APT_String C++ class is NOT the same as the C++ std::string class. The member functions are not the same, nor are operators overloaded in necessarily the same way.
I imagine that your buffer and buffer2 character arrays didn't contain the quite data you were expecting, or that the overloaded ops weren't working in the way you imagined, and that one or the other lead to the error.
A straightforward bit of logic, using the built-in member functions of APT_String, could be:
Code: Select all
match_found = mystring.offsetOfSubstring(" ");
mystring.replace(match_found,1,"");
To stick with a C implementation such as your logic, I think the following would be safer:
Code: Select all
strcpy(buffer,mystring.terminatedContent());
strncpy(buffer2,buffer,match_found);
strcat(buffer2,&buffer[match_found+1]);
mystring = buffer2;
Regards,
- james wiles
All generalizations are false, including this one - Mark Twain.
All generalizations are false, including this one - Mark Twain.