diff options
author | John Wiegley <johnw@newartisans.com> | 2009-10-25 04:35:19 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-10-25 05:01:39 -0400 |
commit | 588f2ef2f51d7bdf209820bfb244034863601939 (patch) | |
tree | 7a473de7c117bf71bb802398823826ca4dfbfdca | |
parent | dc66840dd745863c06ad6513f9f66d589bcc29d8 (diff) | |
download | fork-ledger-588f2ef2f51d7bdf209820bfb244034863601939.tar.gz fork-ledger-588f2ef2f51d7bdf209820bfb244034863601939.tar.bz2 fork-ledger-588f2ef2f51d7bdf209820bfb244034863601939.zip |
Fixed many compiler warnings from g++ 4.4
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | src/accum.cc | 2 | ||||
-rw-r--r-- | src/accum.h | 4 | ||||
-rw-r--r-- | src/amount.cc | 10 | ||||
-rw-r--r-- | src/chain.cc | 8 | ||||
-rw-r--r-- | src/commodity.cc | 9 | ||||
-rw-r--r-- | src/emacs.cc | 4 | ||||
-rw-r--r-- | src/error.cc | 29 | ||||
-rw-r--r-- | src/error.h | 16 | ||||
-rw-r--r-- | src/filters.h | 3 | ||||
-rw-r--r-- | src/format.cc | 14 | ||||
-rw-r--r-- | src/format.h | 12 | ||||
-rw-r--r-- | src/interactive.h | 4 | ||||
-rw-r--r-- | src/item.cc | 2 | ||||
-rw-r--r-- | src/option.cc | 4 | ||||
-rw-r--r-- | src/option.h | 10 | ||||
-rw-r--r-- | src/parser.cc | 11 | ||||
-rw-r--r-- | src/post.cc | 3 | ||||
-rw-r--r-- | src/pyfstream.h | 11 | ||||
-rw-r--r-- | src/pyinterp.cc | 2 | ||||
-rw-r--r-- | src/pyinterp.h | 23 | ||||
-rw-r--r-- | src/report.cc | 32 | ||||
-rw-r--r-- | src/system.hh.in | 4 | ||||
-rw-r--r-- | src/unistring.h | 8 | ||||
-rw-r--r-- | src/utils.cc | 18 | ||||
-rw-r--r-- | src/utils.h | 8 | ||||
-rw-r--r-- | src/value.cc | 11 | ||||
-rw-r--r-- | src/value.h | 5 |
28 files changed, 150 insertions, 123 deletions
diff --git a/configure.ac b/configure.ac index 8b3b791e..ad1c4b37 100644 --- a/configure.ac +++ b/configure.ac @@ -88,7 +88,7 @@ AC_CACHE_CHECK( if (status < 0) { ; } else if (status == 0) { - char *arg0; + char *arg0 = NULL; status = dup2(pfd[0], STDIN_FILENO); @@ -160,8 +160,8 @@ AC_CACHE_CHECK( [[#include <stdlib.h> #include <stdio.h> #include <editline/readline.h>]], - [[rl_readline_name = "foo"; - char * line = readline("foo: "); + [[rl_readline_name = const_cast<char *>("foo"); + char * line = readline(const_cast<char *>("foo: ")); free(line);]])],[libedit_avail_cv_=true],[libedit_avail_cv_=false]) AC_LANG_POP LIBS=$libedit_save_libs]) diff --git a/src/accum.cc b/src/accum.cc index d01d0e52..b918c76a 100644 --- a/src/accum.cc +++ b/src/accum.cc @@ -53,7 +53,7 @@ std::streamsize straccbuf::xsputn(const char * s, std::streamsize num) if (*p == '%') { const char * q = p + 1; if (*q && *q != '%' && std::isdigit(*q) && - std::size_t(*q - '0') == index) { + std::string::size_type(*q - '0') == index) { p++; buf << std::string(s, num); matched = true; diff --git a/src/accum.h b/src/accum.h index caf87d28..c29926d5 100644 --- a/src/accum.h +++ b/src/accum.h @@ -56,8 +56,8 @@ namespace ledger { class straccbuf : public std::streambuf { protected: - std::string str; // accumulator - std::size_t index; + std::string str; // accumulator + std::string::size_type index; public: straccbuf() : index(0) {} diff --git a/src/amount.cc b/src/amount.cc index 2434f110..5aa985c8 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -623,9 +623,9 @@ namespace { "mpfr_print = " << buf << " (precision " << prec << ")"); if (zeros_prec >= 0) { - int index = std::strlen(buf); - int point = 0; - for (int i = 0; i < index; i++) { + string::size_type index = std::strlen(buf); + string::size_type point = 0; + for (string::size_type i = 0; i < index; i++) { if (buf[i] == '.') { point = i; break; @@ -837,7 +837,7 @@ namespace { READ_INTO(in, buf, 255, c, std::isdigit(c) || c == '-' || c == '.' || c == ','); - int len = std::strlen(buf); + string::size_type len = std::strlen(buf); while (len > 0 && ! std::isdigit(buf[len - 1])) { buf[--len] = '\0'; in.unget(); @@ -989,7 +989,7 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags) // necessary. if (last_comma != string::npos || last_period != string::npos) { - int len = quant.length(); + string::size_type len = quant.length(); scoped_array<char> buf(new char[len + 1]); const char * p = quant.c_str(); char * t = buf.get(); diff --git a/src/chain.cc b/src/chain.cc index 7b9083f0..25f4833c 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -65,10 +65,10 @@ post_handler_ptr chain_post_handlers(report_t& report, if (report.HANDLED(head_) || report.HANDLED(tail_)) handler.reset (new truncate_xacts(handler, - report.HANDLED(head_) ? - report.HANDLER(head_).value.to_long() : 0, - report.HANDLED(tail_) ? - report.HANDLER(tail_).value.to_long() : 0)); + report.HANDLED(head_) ? + report.HANDLER(head_).value.to_int() : 0, + report.HANDLED(tail_) ? + report.HANDLER(tail_).value.to_int() : 0)); // filter_posts will only pass through posts matching the // `display_predicate'. diff --git a/src/commodity.cc b/src/commodity.cc index 37f0b573..4041946b 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -498,10 +498,9 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol) char * _p = buf; c = static_cast<char>(in.peek()); while (_p - buf < 255 && in.good() && ! in.eof() && c != '\n') { - int bytes = 0; - int size = _p - buf; - - unsigned char d = c; + std::size_t bytes = 0; + std::ptrdiff_t size = _p - buf; + unsigned char d = c; // Check for the start of a UTF-8 multi-byte encoded string if (d >= 192 && d <= 223 && size < 254) @@ -518,7 +517,7 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol) break; if (bytes > 0) { // we're looking at a UTF-8 encoding - for (int i = 0; i < bytes; i++) { + for (std::size_t i = 0; i < bytes; i++) { in.get(c); if (in.bad() || in.eof()) break; diff --git a/src/emacs.cc b/src/emacs.cc index 4486b67a..57054690 100644 --- a/src/emacs.cc +++ b/src/emacs.cc @@ -41,7 +41,7 @@ namespace ledger { void format_emacs_posts::write_xact(xact_t& xact) { out << "\"" << xact.pathname << "\" " - << (static_cast<std::size_t>(xact.beg_line) + 1) << " "; + << (xact.beg_line + 1) << " "; tm when = gregorian::to_tm(xact.date()); std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local? @@ -77,7 +77,7 @@ void format_emacs_posts::operator()(post_t& post) out << "\n"; } - out << " (" << (static_cast<std::size_t>(post.beg_line) + 1) << " "; + out << " (" << (post.beg_line + 1) << " "; out << "\"" << post.reported_account()->fullname() << "\" \"" << post.amount << "\""; diff --git a/src/error.cc b/src/error.cc index 54d17ad3..70759b08 100644 --- a/src/error.cc +++ b/src/error.cc @@ -47,16 +47,16 @@ string error_context() return context; } -string file_context(const path& file, std::size_t line) +string file_context(const path& file, const std::size_t line) { std::ostringstream buf; buf << "\"" << file << "\", line " << line << ": "; return buf.str(); } -string line_context(const string& line, - std::size_t pos, - std::size_t end_pos) +string line_context(const string& line, + const string::size_type pos, + const string::size_type end_pos) { std::ostringstream buf; buf << " " << line << "\n"; @@ -64,11 +64,11 @@ string line_context(const string& line, if (pos != 0) { buf << " "; if (end_pos == 0) { - for (std::size_t i = 0; i < pos; i += 1) + for (string::size_type i = 0; i < pos; i += 1) buf << " "; buf << "^"; } else { - for (std::size_t i = 0; i < end_pos; i += 1) { + for (string::size_type i = 0; i < end_pos; i += 1) { if (i >= pos) buf << "^"; else @@ -79,12 +79,12 @@ string line_context(const string& line, return buf.str(); } -string source_context(const path& file, - istream_pos_type pos, - istream_pos_type end_pos, - const string& prefix) +string source_context(const path& file, + const istream_pos_type pos, + const istream_pos_type end_pos, + const string& prefix) { - std::streamoff len = end_pos - pos; + const std::streamoff len = end_pos - pos; if (! len || file == path("/dev/stdin")) return _("<no source context>"); @@ -97,10 +97,9 @@ string source_context(const path& file, in.seekg(pos, std::ios::beg); scoped_array<char> buf(new char[len + 1]); - in.read(buf.get(), static_cast<int>(len)); - assert(static_cast<std::size_t>(in.gcount()) == - static_cast<std::size_t>(len)); - buf[static_cast<int>(len)] = '\0'; + in.read(buf.get(), len); + assert(in.gcount() == len); + buf[len] = '\0'; bool first = true; for (char * p = std::strtok(buf.get(), "\n"); diff --git a/src/error.h b/src/error.h index 42eab8d9..21f5bd8f 100644 --- a/src/error.h +++ b/src/error.h @@ -87,14 +87,14 @@ extern std::ostringstream _ctxt_buffer; string error_context(); string file_context(const path& file, std::size_t line); -string line_context(const string& line, - std::size_t pos = 0, - std::size_t end_pos = 0); - -string source_context(const path& file, - istream_pos_type pos, - istream_pos_type end_pos, - const string& prefix = ""); +string line_context(const string& line, + const string::size_type pos = 0, + const string::size_type end_pos = 0); + +string source_context(const path& file, + const istream_pos_type pos, + const istream_pos_type end_pos, + const string& prefix = ""); #define DECLARE_EXCEPTION(name, kind) \ class name : public kind { \ diff --git a/src/filters.h b/src/filters.h index 050e3dcf..a03d3160 100644 --- a/src/filters.h +++ b/src/filters.h @@ -142,7 +142,8 @@ class truncate_xacts : public item_handler<post_t> truncate_xacts(); public: - truncate_xacts(post_handler_ptr handler, int _head_count, int _tail_count) + truncate_xacts(post_handler_ptr handler, + int _head_count, int _tail_count) : item_handler<post_t>(handler), head_count(_head_count), tail_count(_tail_count), xacts_seen(0), last_xact(NULL) { diff --git a/src/format.cc b/src/format.cc index ecac1133..35f3d80f 100644 --- a/src/format.cc +++ b/src/format.cc @@ -345,7 +345,7 @@ void format_t::format(std::ostream& out_str, scope_t& scope) } DEBUG("format.expr", "value = (" << value << ")"); - value.print(out, elem->min_width, -1, + value.print(out, static_cast<int>(elem->min_width), -1, ! elem->has_flags(ELEMENT_ALIGN_LEFT)); } catch (const calc_error&) { @@ -362,14 +362,13 @@ void format_t::format(std::ostream& out_str, scope_t& scope) if (elem->max_width > 0 || elem->min_width > 0) { unistring temp(out.str()); + string result; - string result; if (elem->max_width > 0 && elem->max_width < temp.length()) { result = truncate(temp, elem->max_width); } else { result = temp.extract(); - for (int i = 0; i < (static_cast<int>(elem->min_width) - - static_cast<int>(temp.length())); i++) + for (std::size_t i = 0; i < elem->min_width - temp.length(); i++) result += " "; } out_str << result; @@ -379,8 +378,9 @@ void format_t::format(std::ostream& out_str, scope_t& scope) } } -string format_t::truncate(const unistring& ustr, std::size_t width, - const int account_abbrev_length) +string format_t::truncate(const unistring& ustr, + const std::size_t width, + const std::size_t account_abbrev_length) { assert(width < 4095); @@ -434,7 +434,7 @@ string format_t::truncate(const unistring& ustr, std::size_t width, if (newlen > width) { unistring temp(*i); - if (temp.length() > static_cast<std::size_t>(account_abbrev_length)) { + if (temp.length() > account_abbrev_length) { result << temp.extract(0, account_abbrev_length) << ":"; newlen -= temp.length() - account_abbrev_length; } else { diff --git a/src/format.h b/src/format.h index 03ed28c7..bc513f71 100644 --- a/src/format.h +++ b/src/format.h @@ -65,10 +65,7 @@ class format_t : public noncopyable { #define ELEMENT_ALIGN_LEFT 0x01 - enum kind_t { - STRING, - EXPR, - }; + enum kind_t { STRING, EXPR }; kind_t type; std::size_t min_width; @@ -89,7 +86,7 @@ class format_t : public noncopyable friend inline void mark_red(std::ostream& out, const element_t * elem) { out.setf(std::ios::left); out.width(0); - out << "\e[31m"; + out << "\033[31m"; if (elem->has_flags(ELEMENT_ALIGN_LEFT)) out << std::left; @@ -145,8 +142,9 @@ public: elem->dump(out); } - static string truncate(const unistring& str, std::size_t width, - const int account_abbrev_length = -1); + static string truncate(const unistring& str, + const std::size_t width, + const std::size_t account_abbrev_length = 0); }; #define FMT_PREFIX "fmt_" diff --git a/src/interactive.h b/src/interactive.h index a0388726..0396b1c8 100644 --- a/src/interactive.h +++ b/src/interactive.h @@ -92,6 +92,10 @@ inline bool interactive_t::get<bool>(std::size_t index) { return value_at(index).to_boolean(); } template <> +inline int interactive_t::get<int>(std::size_t index) { + return value_at(index).to_int(); +} +template <> inline long interactive_t::get<long>(std::size_t index) { return value_at(index).to_long(); } diff --git a/src/item.cc b/src/item.cc index 54f36e11..c4db7a51 100644 --- a/src/item.cc +++ b/src/item.cc @@ -142,7 +142,7 @@ void item_t::parse_tags(const char * p, optional<date_t::year_type> current_year for (char * q = std::strtok(buf.get(), " \t"); q; q = std::strtok(NULL, " \t")) { - const std::size_t len = std::strlen(q); + const string::size_type len = std::strlen(q); if (! tag.empty()) { if (! has_tag(tag)) set_tag(tag, string(p + (q - buf.get()))); diff --git a/src/option.cc b/src/option.cc index 1275e270..f47410e2 100644 --- a/src/option.cc +++ b/src/option.cc @@ -110,8 +110,8 @@ void process_option(const string& whence, const string& name, scope_t& scope, void process_environment(const char ** envp, const string& tag, scope_t& scope) { - const char * tag_p = tag.c_str(); - std::size_t tag_len = tag.length(); + const char * tag_p = tag.c_str(); + string::size_type tag_len = tag.length(); for (const char ** p = envp; *p; p++) { if (! tag_p || std::strncmp(*p, tag_p, tag_len) == 0) { diff --git a/src/option.h b/src/option.h index 6809a27c..89f1ad08 100644 --- a/src/option.h +++ b/src/option.h @@ -56,11 +56,11 @@ template <typename T> class option_t { protected: - const char * name; - std::size_t name_len; - const char ch; - bool handled; - optional<string> source; + const char * name; + string::size_type name_len; + const char ch; + bool handled; + optional<string> source; option_t& operator=(const option_t&); diff --git a/src/parser.cc b/src/parser.cc index 39004758..a6053d69 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -491,9 +491,10 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags, if (original_string) { add_error_context(_("While parsing value expression:")); - std::size_t end_pos = - in.good() ? static_cast<std::size_t>(in.tellg()) : 0; - std::size_t pos = static_cast<std::size_t>(end_pos); + std::streamoff end_pos = 0; + if (in.good()) + end_pos = in.tellg(); + std::streamoff pos = end_pos; if (pos > 0) pos -= lookahead.length; @@ -504,7 +505,9 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags, DEBUG("parser.error", " token kind = " << int(lookahead.kind)); DEBUG("parser.error", " token length = " << lookahead.length); - add_error_context(line_context(*original_string, pos, end_pos)); + add_error_context(line_context(*original_string, + static_cast<string::size_type>(pos), + static_cast<string::size_type>(end_pos))); } throw; } diff --git a/src/post.cc b/src/post.cc index 9b416434..90c10a3b 100644 --- a/src/post.cc +++ b/src/post.cc @@ -195,7 +195,8 @@ namespace { string name = env->reported_account()->fullname(); if (env.has(0) && env.get<long>(0) > 2) - name = format_t::truncate(name, env.get<long>(0) - 2, true); + name = format_t::truncate(name, env.get<long>(0) - 2, + 2 /* account_abbrev_length */); if (env->has_flags(POST_VIRTUAL)) { if (env->must_balance()) diff --git a/src/pyfstream.h b/src/pyfstream.h index 5e39d38d..3da37523 100644 --- a/src/pyfstream.h +++ b/src/pyfstream.h @@ -109,9 +109,9 @@ protected: * - at most, pbSize characters in putback area plus * - at most, bufSize characters in ordinary read buffer */ - static const int pbSize = 4; // size of putback area - static const int bufSize = 1024; // size of the data buffer - char buffer[bufSize + pbSize]; // data buffer + static const size_t pbSize = 4; // size of putback area + static const size_t bufSize = 1024; // size of the data buffer + char buffer[bufSize + pbSize]; // data buffer public: /* constructor @@ -147,7 +147,7 @@ protected: * - use number of characters read * - but at most size of putback area */ - int numPutback; + size_t numPutback; numPutback = gptr() - eback(); if (numPutback > pbSize) { numPutback = pbSize; @@ -160,14 +160,13 @@ protected: numPutback); // read at most bufSize new characters - int num; PyObject *line = PyFile_GetLine(reinterpret_cast<PyObject *>(fo), bufSize); if (! line || ! PyString_Check(line)) { // ERROR or EOF return EOF; } - num = PyString_Size(line); + Py_ssize_t num = PyString_Size(line); if (num == 0) return EOF; diff --git a/src/pyinterp.cc b/src/pyinterp.cc index a163175f..f5b1a543 100644 --- a/src/pyinterp.cc +++ b/src/pyinterp.cc @@ -266,7 +266,7 @@ value_t python_interpreter_t::python_command(call_scope_t& args) std::strcpy(argv[i + 1], arg.c_str()); } - int status = Py_Main(args.size() + 1, argv); + int status = Py_Main(static_cast<int>(args.size()) + 1, argv); for (std::size_t i = 0; i < args.size() + 1; i++) delete[] argv[i]; diff --git a/src/pyinterp.h b/src/pyinterp.h index dd9ca64c..4943eb2f 100644 --- a/src/pyinterp.h +++ b/src/pyinterp.h @@ -105,6 +105,7 @@ public: virtual expr_t::ptr_op_t lookup(const string& name); +#if BOOST_VERSION >= 103700 OPTION_(python_interpreter_t, import_, DO_(scope) { interactive_t args(scope, "s"); @@ -114,23 +115,31 @@ public: python::object sys_dict = module_sys.attr("__dict__"); python::list paths(sys_dict["path"]); -#if BOOST_VERSION >= 103700 paths.insert(0, file.parent_path().string()); -#else - paths.insert(0, file.branch_path().string()); -#endif sys_dict["path"] = paths; -#if BOOST_VERSION >= 103700 string name = file.filename(); if (contains(name, ".py")) parent->import(file.stem()); else parent->import(name); -#else + }); +#else // BOOST_VERSION >= 103700 + OPTION_(python_interpreter_t, import_, DO_(scope) { + interactive_t args(scope, "s"); + + path file(args.get<string>(0)); + + python::object module_sys = parent->import("sys"); + python::object sys_dict = module_sys.attr("__dict__"); + + python::list paths(sys_dict["path"]); + paths.insert(0, file.branch_path().string()); + sys_dict["path"] = paths; + parent->import(file.leaf()); -#endif }); +#endif // BOOST_VERSION >= 103700 }; extern shared_ptr<python_interpreter_t> python_session; diff --git a/src/report.cc b/src/report.cc index 4c8a40e6..661fdfbe 100644 --- a/src/report.cc +++ b/src/report.cc @@ -211,8 +211,8 @@ value_t report_t::fn_truncated(call_scope_t& scope) interactive_t args(scope, "v&ll"); return string_value(format_t::truncate (args.get<string>(0), - args.has(1) && args.get<long>(1) > 0 ? args.get<long>(1) : 0, - args.has(2) ? args.get<long>(2) : -1)); + args.has(1) && args.get<int>(1) > 0 ? args.get<int>(1) : 0, + args.has(2) ? args.get<int>(2) : 0)); } value_t report_t::fn_justify(call_scope_t& scope) @@ -220,8 +220,8 @@ value_t report_t::fn_justify(call_scope_t& scope) interactive_t args(scope, "vl&lbbs"); std::ostringstream out; args.value_at(0) - .print(out, args.get<long>(1), - args.has(2) ? args.get<long>(2) : -1, + .print(out, args.get<int>(1), + args.has(2) ? args.get<int>(2) : -1, args.has(3) ? args.get<bool>(3) : false, args.has(4) ? args.get<bool>(4) : false, args.has(5) ? args.get<string>(5) : @@ -275,19 +275,19 @@ value_t report_t::fn_ansify_if(call_scope_t& scope) if (args.has(1)) { string color = args.get<string>(1); std::ostringstream buf; - if (color == "black") buf << "\e[30m"; - else if (color == "red") buf << "\e[31m"; - else if (color == "green") buf << "\e[32m"; - else if (color == "yellow") buf << "\e[33m"; - else if (color == "blue") buf << "\e[34m"; - else if (color == "magenta") buf << "\e[35m"; - else if (color == "cyan") buf << "\e[36m"; - else if (color == "white") buf << "\e[37m"; - else if (color == "bold") buf << "\e[1m"; - else if (color == "underline") buf << "\e[4m"; - else if (color == "blink") buf << "\e[5m"; + if (color == "black") buf << "\033[30m"; + else if (color == "red") buf << "\033[31m"; + else if (color == "green") buf << "\033[32m"; + else if (color == "yellow") buf << "\033[33m"; + else if (color == "blue") buf << "\033[34m"; + else if (color == "magenta") buf << "\033[35m"; + else if (color == "cyan") buf << "\033[36m"; + else if (color == "white") buf << "\033[37m"; + else if (color == "bold") buf << "\033[1m"; + else if (color == "underline") buf << "\033[4m"; + else if (color == "blink") buf << "\033[5m"; buf << args.value_at(0); - buf << "\e[0m"; + buf << "\033[0m"; return string_value(buf.str()); } else { return args.value_at(0); diff --git a/src/system.hh.in b/src/system.hh.in index 2a6b41af..07598173 100644 --- a/src/system.hh.in +++ b/src/system.hh.in @@ -83,8 +83,8 @@ namespace std { } } -typedef std::size_t istream_pos_type; -typedef std::size_t ostream_pos_type; +typedef std::streamoff istream_pos_type; +typedef std::streamoff ostream_pos_type; #else // ! (defined(__GNUG__) && __GNUG__ < 3) diff --git a/src/unistring.h b/src/unistring.h index 5467a151..d3cfc126 100644 --- a/src/unistring.h +++ b/src/unistring.h @@ -103,9 +103,9 @@ inline void justify(std::ostream& out, bool redden = false) { if (! right) { - if (redden) out << "\e[31m"; + if (redden) out << "\033[31m"; out << str; - if (redden) out << "\e[0m"; + if (redden) out << "\033[0m"; } unistring temp(str); @@ -115,9 +115,9 @@ inline void justify(std::ostream& out, out << ' '; if (right) { - if (redden) out << "\e[31m"; + if (redden) out << "\033[31m"; out << str; - if (redden) out << "\e[0m"; + if (redden) out << "\033[0m"; } } diff --git a/src/utils.cc b/src/utils.cc index f2449daf..1cdbb9a0 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -402,17 +402,19 @@ string::string(const char * str) : std::string(str) { string::string(const char * str, const char * end) : std::string(str, end) { TRACE_CTOR(string, "const char *, const char *"); } -string::string(const string& str, int x) : std::string(str, x) { - TRACE_CTOR(string, "const string&, int"); +string::string(const string& str, size_type x) : std::string(str, x) { + TRACE_CTOR(string, "const string&, size_type"); } -string::string(const string& str, int x, int y) : std::string(str, x, y) { - TRACE_CTOR(string, "const string&, int, int"); +string::string(const string& str, size_type x, size_type y) + : std::string(str, x, y) { + TRACE_CTOR(string, "const string&, size_type, size_type"); } -string::string(const char * str, int x) : std::string(str, x) { - TRACE_CTOR(string, "const char *, int"); +string::string(const char * str, size_type x) : std::string(str, x) { + TRACE_CTOR(string, "const char *, size_type"); } -string::string(const char * str, int x, int y) : std::string(str, x, y) { - TRACE_CTOR(string, "const char *, int, int"); +string::string(const char * str, size_type x, size_type y) + : std::string(str, x, y) { + TRACE_CTOR(string, "const char *, size_type, size_type"); } string::~string() throw() { TRACE_DTOR(string); diff --git a/src/utils.h b/src/utils.h index 462cef52..7042ddf6 100644 --- a/src/utils.h +++ b/src/utils.h @@ -173,10 +173,10 @@ public: string(size_type len, char x); string(const char * str); string(const char * str, const char * end); - string(const string& str, int x); - string(const string& str, int x, int y); - string(const char * str, int x); - string(const char * str, int x, int y); + string(const string& str, size_type x); + string(const string& str, size_type x, size_type y); + string(const char * str, size_type x); + string(const char * str, size_type x, size_type y); ~string() throw(); }; diff --git a/src/value.cc b/src/value.cc index 702b889e..0f831cdf 100644 --- a/src/value.cc +++ b/src/value.cc @@ -173,6 +173,17 @@ date_t value_t::to_date() const } } +int value_t::to_int() const +{ + if (is_long()) { + return static_cast<int>(as_long()); + } else { + value_t temp(*this); + temp.in_place_cast(INTEGER); + return static_cast<int>(temp.as_long()); + } +} + long value_t::to_long() const { if (is_long()) { diff --git a/src/value.h b/src/value.h index 62943e62..f6194c86 100644 --- a/src/value.h +++ b/src/value.h @@ -733,6 +733,7 @@ public: * exception is thrown. */ bool to_boolean() const; + int to_int() const; long to_long() const; datetime_t to_datetime() const; date_t to_date() const; @@ -788,7 +789,7 @@ public: /** * Collection-style access methods for SEQUENCE values. */ - value_t& operator[](const int index) { + value_t& operator[](const std::size_t index) { VERIFY(! is_null()); if (is_sequence()) return as_sequence_lval()[index]; @@ -799,7 +800,7 @@ public: static value_t null; return null; } - const value_t& operator[](const int index) const { + const value_t& operator[](const std::size_t index) const { VERIFY(! is_null()); if (is_sequence()) return as_sequence()[index]; |