29 */ |
29 */ |
30 |
30 |
31 #include <cstdio> |
31 #include <cstdio> |
32 #include "format.h" |
32 #include "format.h" |
33 |
33 |
34 // |
34 // ------------------------------------------------------------------------------------------------- |
35 // Throws an error while formatting the string |
35 // Throws an error while formatting the string |
36 // |
36 // |
37 static auto format_error (String fmtstr, const String errdescribe, int pos) -> void |
37 static auto format_error (String fmtstr, const String errdescribe, int pos) -> void |
38 { |
38 { |
39 fmtstr.replace ("\n", " "); |
39 fmtstr.replace ("\n", " "); |
42 |
42 |
43 for (int x = 0; x < pos; ++x) |
43 for (int x = 0; x < pos; ++x) |
44 errmsg += "-"; |
44 errmsg += "-"; |
45 |
45 |
46 errmsg += "^\n" + errdescribe; |
46 errmsg += "^\n" + errdescribe; |
47 // throw std::logic_error (errmsg.stdString()); |
47 throw std::logic_error (errmsg.std_string()); |
48 std::fprintf (stderr, "%s", errmsg.chars()); |
|
49 std::exit (EXIT_FAILURE); |
|
50 } |
48 } |
51 |
49 |
52 // |
50 // ------------------------------------------------------------------------------------------------- |
53 // Main formatter algorithm autoion. Processes @fmtstr with @args and returns |
51 // Main formatter algorithm. |
54 // the result. |
|
55 // |
52 // |
56 auto format_args (const String& fmtstr, const Vector<String>& args) -> String |
53 auto format_args (const String& fmtstr, const Vector<String>& args) -> String |
57 { |
54 { |
58 String fmt = fmtstr; |
55 String fmt = fmtstr; |
59 int pos = 0; |
56 int pos = 0; |