Print corner coodinates in decimal form for more precision.
[gocam.git] / str.hh
blobbb5da85f8ce83475c089fccf801efb0abb5dd7c1
1 #include <string>
2 #include <vector>
3 #include <stdio.h>
5 /** Functions for handling strings of the Standard Template Library. */
6 namespace str {
8 /** Read a line from a file.
9 * \param str = the string to read to
10 * \param file = the file to read from
11 * \param do_chomp = should we chomp the possible newline at the end
12 * \return false if no more lines in the file
14 bool read_line(std::string *str, FILE *file = stdin, bool do_chomp = false);
16 /** Read a string of given length from a file.
17 * \param str = the string to read to
18 * \param length = the bytes to read
19 * \param file = the file to read from
20 * \return false if could not read length bytes
22 bool read_string(std::string *str, size_t length, FILE *file = stdin);
24 /** Read a file to string.
25 * \param str = the string to read to
26 * \param file = the file to read from
27 * \param length = the maximum size of the file (0 = read all)
28 * \return false if read failed for some reason (see errno for details)
30 bool read_file(std::string *str, FILE *file, size_t length = 0);
32 /** Remove the possible trailing newline from a string. */
33 void chomp(std::string *str);
35 /** Remove leading and trailing characters from a string.
36 * \param str = the string to be cleaned
37 * \param chars = the characters to clean from the string
39 void clean(std::string *str, const char *chars);
41 /** Split a string to fields. If \c num_fields is positive, it
42 * specifies the maximum number of fields. If the line contains
43 * more fields, they are included in the last field as such (also
44 * possible delimiters without processing).
46 * \param str = the string to be splitted
47 * \param delims = the delimiter characters
48 * \param group = group subsequent delimiters as one delimeter
49 * \param fields = the vector containing the resulting fields
50 * \param num_fields = the maximum number of fields to return
52 void
53 split(const std::string *str, const char *delims, bool group,
54 std::vector<std::string> *fields, int num_fields = 0);
56 /** Split a string to fields while processing quotes \, ', ".
58 * The function modifies \c str by removing quotes and preserving
59 * only the first delimiter from groups of delimiters. All quotation
60 * marks can be used to quote other quotation marks, and backslash
61 * can be used to quote backslash too.
63 * \warning Delimeters must not include quotation chars.
65 * \param str = the string to be splitted
66 * \param delims = the delimiter characters
67 * \param group = group subsequent delimiters as one delimeter
68 * \param fields = the vector containing the resulting fields
70 void
71 split_with_quotes(std::string *str, const char *delims, bool group,
72 std::vector<std::string> *fields);
74 /** Convert a string to numeric value.
75 * \param str = the string to convert
76 * \param ok = set to false if the whole string could not be converted.
77 * \return the numeric value.
79 /*@{*/
80 long str2long(const char *str, bool *ok);
81 double str2float(const char *str, bool *ok);
82 long str2long(std::string *str, bool *ok);
83 double str2float(std::string *str, bool *ok);
84 /*@}*/