From 4249b13f4c317ae4d0f0cf7b5e6a78acdfdc47fa Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Tue, 18 Jun 2024 23:34:40 +0800 Subject: [PATCH 1/3] [2_1] Cork: tm_encode --- tests/Data/String/cork_test.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/Data/String/cork_test.cpp diff --git a/tests/Data/String/cork_test.cpp b/tests/Data/String/cork_test.cpp new file mode 100644 index 0000000..ccc8602 --- /dev/null +++ b/tests/Data/String/cork_test.cpp @@ -0,0 +1,21 @@ + +/****************************************************************************** + * 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 . + ******************************************************************************/ + +#include "modification.hpp" +#include "moe_doctests.hpp" +#include "tree.hpp" + +TEST_CASE ("tm_encode") { + string_eq (tm_encode ("<>"), ""); + string_eq (tm_encode ("<#ABCD>"), "#ABCD"); + string_eq (tm_encode ("abc", "abc")); + string_eq (tm_encode ("", "")); +} From 912d15a7bc3dfc5f262d1e8fbf031ac89b9f6364 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Tue, 18 Jun 2024 23:38:56 +0800 Subject: [PATCH 2/3] wip --- tests/Data/String/cork_test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Data/String/cork_test.cpp b/tests/Data/String/cork_test.cpp index ccc8602..1c47572 100644 --- a/tests/Data/String/cork_test.cpp +++ b/tests/Data/String/cork_test.cpp @@ -9,6 +9,7 @@ * in the root directory or . ******************************************************************************/ +#include "cork.hpp" #include "modification.hpp" #include "moe_doctests.hpp" #include "tree.hpp" @@ -16,6 +17,6 @@ TEST_CASE ("tm_encode") { string_eq (tm_encode ("<>"), ""); string_eq (tm_encode ("<#ABCD>"), "#ABCD"); - string_eq (tm_encode ("abc", "abc")); - string_eq (tm_encode ("", "")); + string_eq (tm_encode ("abc"), "abc"); + string_eq (tm_encode (""), ""); } From 91fb9ef4a02786f08ff5b6faeebf9ed7002e61dc Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Tue, 18 Jun 2024 23:42:12 +0800 Subject: [PATCH 3/3] wip --- Data/String/cork.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Data/String/cork.cpp b/Data/String/cork.cpp index 67c0689..75f5f6d 100644 --- a/Data/String/cork.cpp +++ b/Data/String/cork.cpp @@ -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 << ""; - else if (s[i] == '>') r << ""; - else r << s[i]; + for (const auto ch : s) { + if (ch == '<') r << ""; + else if (ch == '>') r << ""; + else r << ch; } return r; }