Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2_1] Cork: faster tm_encode #31

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (""), "");
}
Loading