![]() |
【转帖】odstringgetlength90 question
odstring::getlength() question
odstring::getlength() question i just tracked down a bug in my mtext processing that was caused by an incorrect return value from getlength(). specifically the sp_mtx->contents().getlength() value seems to be one high (in other words it includes the trailing null). ("sp_mtx" is a smart pointer to an oddbmtext object.) i fixed it by using strlen(sp_mtx->contents().c_str()) instead. could this be a bug in your code? i can't imagine that no one would have noticed by now... thanks, -jimc quote: originally posted by exeye could this be a bug in your code? i can't imagine that no one would have noticed by now... -jimc i have noticed the behavior too. i think length refers to buffer length and not string length. whatever it is, i believe, it is a feature not a bug. - jaydutt shuklafff"> quote: originally posted by jaydutt i have noticed the behavior too. i think length refers to buffer length and not string length. whatever it is, i believe, it is a feature not a bug. the reasons that i think this should be considered a bug are: 1. the documentation says that the function "returns the number of characters in this string". 2. all string length functions i know of return the length without the null terminating byte. at the very least the documentation should make this peculiar behavior very clear. -jimc odstring stores data length and returns it from getlength(). example: code: odstring str; str = "a"; int len = str.getlength(); // len = 1 str = "a\0"; len = str.getlength(); // len = 1 (because strlen is used to calculate const string length str += '\0'; len = str.getlength(); // len = 2 - character is appended how mtext with contents having extra length (together with null terminator) was created? sergey slezkin i am using a drawing created by a client, using autocad 2000 i think. i can send it privately if you want (give me an email address) but don't want to post it publicly as it is not mine. the code used to read it is: // get pointer to mtext entity oddbmtextptr sp_mtx = id_ent.safeopenobject(); // get text str_txt = sp_mtx->contents(); nchmtx = strlen(str_txt.c_str()); originally i was using: nchmtx = str_txt.getlength(); in place of the last line. when i traced the results of the two lines they were different. if i can give you any more info, please ask. sorry for the unconventional coding style; i like short variable names. -jimc my e-mail is sslezkin_at_softdev_dot_spb_dot_ru it would be interesting to look at the file showing this problem (minimized version with single mtext entity would be enough if you do not want to share client's file) sergey slezkin |
所有的时间均为北京时间。 现在的时间是 09:16 PM. |