Skip to content

Commit

Permalink
[2_1] Cork: faster tm_encode
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Jun 18, 2024
1 parent 7f1e380 commit 72cce70
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Data/String/cork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ contains_unicode_char (string s) {
string
tm_encode (string s) {
// verbatim to TeXmacs encoding
int i;
string r;
for (i= 0; i < N (s); i++) {
if (s[i] == '<') r << "<less>";
else if (s[i] == '>') r << "<gtr>";
else r << s[i];
for (const auto ch : s) {
if (ch == '<') r << "<less>";
else if (ch == '>') r << "<gtr>";
else r << ch;
}
return r;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Data/String/cork_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

/******************************************************************************
* MODULE : cork_test.cpp
* DESCRIPTION: tests for the Cork encoding
* COPYRIGHT : (C) 2024 Darcy Shen
*******************************************************************************
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/

#include "cork.hpp"
#include "modification.hpp"
#include "moe_doctests.hpp"
#include "tree.hpp"

TEST_CASE ("tm_encode") {
string_eq (tm_encode ("<>"), "<less><gtr>");
string_eq (tm_encode ("<#ABCD>"), "<less>#ABCD<gtr>");
string_eq (tm_encode ("abc"), "abc");
string_eq (tm_encode (""), "");
}

0 comments on commit 72cce70

Please sign in to comment.