itok function implemented
This commit is contained in:
parent
22406e1314
commit
deb483b83d
|
|
@ -14,6 +14,11 @@ std::string mini_sprintf_format(bool left_align, bool sign, bool space_on_left,
|
||||||
if (specifier == 's') {
|
if (specifier == 's') {
|
||||||
return value.as_string();
|
return value.as_string();
|
||||||
}
|
}
|
||||||
|
if (specifier == 'c') {
|
||||||
|
std::ostringstream stream_str;
|
||||||
|
stream_str << (char) value.as_int();
|
||||||
|
return stream_str.str();
|
||||||
|
}
|
||||||
if (specifier == 'i' || specifier == 'd') {
|
if (specifier == 'i' || specifier == 'd') {
|
||||||
int ival = value.as_int();
|
int ival = value.as_int();
|
||||||
is_positive = ival >= 0;
|
is_positive = ival >= 0;
|
||||||
|
|
@ -96,6 +101,7 @@ std::string mini_sprintf(const std::string &format_str, const std::vector<MlValu
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'f':
|
case 'f':
|
||||||
|
case 'c':
|
||||||
case 's':
|
case 's':
|
||||||
bool left_align = false;
|
bool left_align = false;
|
||||||
bool sign = false;
|
bool sign = false;
|
||||||
|
|
@ -156,7 +162,7 @@ std::string mini_sprintf(const std::string &format_str, const std::vector<MlValu
|
||||||
// specifier
|
// specifier
|
||||||
if (si >= format_str.end())
|
if (si >= format_str.end())
|
||||||
return output_str; // invalid end of string
|
return output_str; // invalid end of string
|
||||||
if (*si == 'i' || *si == 'd' || *si == 'f' || *si == 's') { // TODO more specifiers
|
if (*si == 'i' || *si == 'd' || *si == 'f' || *si == 's' || *si == 'c') { // TODO more specifiers
|
||||||
std::string s = mini_sprintf_format(left_align, sign, space_on_left, padding_by_zero, width, precision, length, *si, parameters[arg_position]);
|
std::string s = mini_sprintf_format(left_align, sign, space_on_left, padding_by_zero, width, precision, length, *si, parameters[arg_position]);
|
||||||
arg_position++;
|
arg_position++;
|
||||||
output_str += s;
|
output_str += s;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
// Replace a substring with a replacement string in a source string
|
|
||||||
void replace_substring(std::string &src, const std::string &substr, const std::string &replacement);
|
void replace_substring(std::string &src, const std::string &substr, const std::string &replacement);
|
||||||
|
|
||||||
// Returns true if where contains regex
|
// Returns true if where contains regex
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@
|
||||||
rslt
|
rslt
|
||||||
))
|
))
|
||||||
|
|
||||||
|
(defun itok (ascii) (sprintf "%c" (list ascii)))
|
||||||
|
|
||||||
; pause for interval of seconds
|
; pause for interval of seconds
|
||||||
(defun sleep (time)
|
(defun sleep (time)
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,9 @@
|
||||||
(ut::define-test "result of (string-find \" long long int;\" \"o\")" '(ut::assert-equal 2 (string-find " long long int;" "o")))
|
(ut::define-test "result of (string-find \" long long int;\" \"o\")" '(ut::assert-equal 2 (string-find " long long int;" "o")))
|
||||||
(ut::define-test "result of (string-find \" long long int;\" \"float\")" '(ut::assert-nil (string-find " long long int;" "float")))
|
(ut::define-test "result of (string-find \" long long int;\" \"float\")" '(ut::assert-nil (string-find " long long int;" "float")))
|
||||||
|
|
||||||
|
(ut::define-test "result of (itok 65)" '(ut::assert-equal "A" (itok 65)))
|
||||||
|
(ut::define-test "result of (itok 48)" '(ut::assert-equal "0" (itok 48)))
|
||||||
|
|
||||||
(ut::define-test "result of (write-file \"/tmp/file\" \"write-file test\")" '(ut::assert-equal 1 (write-file "/tmp/file" "write-file test\n")))
|
(ut::define-test "result of (write-file \"/tmp/file\" \"write-file test\")" '(ut::assert-equal 1 (write-file "/tmp/file" "write-file test\n")))
|
||||||
(ut::define-test "result of (is-file? \"/tmp/file\")" '(ut::assert-true (is-file? "/tmp/file")))
|
(ut::define-test "result of (is-file? \"/tmp/file\")" '(ut::assert-true (is-file? "/tmp/file")))
|
||||||
(ut::define-test "result of (is-file? \"/tmp/file_whichnotex_ists\")" '(ut::assert-false (is-file? "/tmp/file_whichnotex_ists")))
|
(ut::define-test "result of (is-file? \"/tmp/file_whichnotex_ists\")" '(ut::assert-false (is-file? "/tmp/file_whichnotex_ists")))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue