Skip to content

Commit

Permalink
Utils: reimplement uprintf() with bash echo
Browse files Browse the repository at this point in the history
  • Loading branch information
soimort committed Dec 16, 2017
1 parent 5b90d2c commit 4536adc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions include/Utils.awk
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,10 @@ function base64(text, command, temp) {
return temp
}

# Print a Unicode-escaped string. (GNU only)
# FIXME: find a BSD/macOS equivalent
# Print a Unicode-escaped string. (requires GNU Bash)
# NOTE: can only be ran once for each text! Build a cache.
function uprintf(text, command, temp) {
command = "printf"
(command " -- " parameterize(text) | getline temp)
command = "echo -en " parameterize(text)
("bash -c " parameterize(command, "\"")) | getline temp
return temp
}
8 changes: 4 additions & 4 deletions test/TestUtils.awk
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ BEGIN {
assertEqual(base64("ninja"), "bmluamE=")
}

#T("uprintf", 1)
#{
# assertEqual(uprintf("Ma\\u00f1ana"), "Mañana")
#}
T("uprintf", 1)
{
assertEqual(uprintf("Ma\\u00f1ana"), "Mañana")
}

END_TEST()
}

0 comments on commit 4536adc

Please sign in to comment.