stl and sprints/sscans
-
Im trying to program an STL version of sprints and sscans using stl strings to format a variable number of arguments and print to or read from a string, but have become hopelessly lost in format flags/precisions etc. Function headers i would like to expose are: int SPrintS( std::string buffer, const std::string format, ...); ... and ...:confused: int SScanS( std::string buffer, const std::string format, ...); Both functions return the number of chars read/written to the string or -1 on conversion failure. In the implementation of these functions i dont want to call the c version of sprints or sscans (or svprintf etc). I understand how to deal with variable arguments, the problem im having is in parsing the format specifier, it takes the general form: %[flags] [width] [.precision] [{h | l | I64 | L}]type My attempts at a parse function always seems to become unruly then break down before it can cope with the complete range of optional prefixes to a type (those within [] ), that coupled with format strings can contain any number of format specifiers. Any suggstions as to the way forward would be welcomed.
-
Im trying to program an STL version of sprints and sscans using stl strings to format a variable number of arguments and print to or read from a string, but have become hopelessly lost in format flags/precisions etc. Function headers i would like to expose are: int SPrintS( std::string buffer, const std::string format, ...); ... and ...:confused: int SScanS( std::string buffer, const std::string format, ...); Both functions return the number of chars read/written to the string or -1 on conversion failure. In the implementation of these functions i dont want to call the c version of sprints or sscans (or svprintf etc). I understand how to deal with variable arguments, the problem im having is in parsing the format specifier, it takes the general form: %[flags] [width] [.precision] [{h | l | I64 | L}]type My attempts at a parse function always seems to become unruly then break down before it can cope with the complete range of optional prefixes to a type (those within [] ), that coupled with format strings can contain any number of format specifiers. Any suggstions as to the way forward would be welcomed.
-
Im trying to program an STL version of sprints and sscans using stl strings to format a variable number of arguments and print to or read from a string, but have become hopelessly lost in format flags/precisions etc. Function headers i would like to expose are: int SPrintS( std::string buffer, const std::string format, ...); ... and ...:confused: int SScanS( std::string buffer, const std::string format, ...); Both functions return the number of chars read/written to the string or -1 on conversion failure. In the implementation of these functions i dont want to call the c version of sprints or sscans (or svprintf etc). I understand how to deal with variable arguments, the problem im having is in parsing the format specifier, it takes the general form: %[flags] [width] [.precision] [{h | l | I64 | L}]type My attempts at a parse function always seems to become unruly then break down before it can cope with the complete range of optional prefixes to a type (those within [] ), that coupled with format strings can contain any number of format specifiers. Any suggstions as to the way forward would be welcomed.
Hi, There is an article by Sutter on this issue. If you are interested, you can read it here: http://www.gotw.ca/publications/mill19.htm Also, there is an experimental c++ string format library (It is accepted by the boost organizers) : http://groups.yahoo.com/group/boost/files/format2/ Regards, Lirong
-
Hi, There is an article by Sutter on this issue. If you are interested, you can read it here: http://www.gotw.ca/publications/mill19.htm Also, there is an experimental c++ string format library (It is accepted by the boost organizers) : http://groups.yahoo.com/group/boost/files/format2/ Regards, Lirong