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

[19_1] unicode_get_range migrated from mogan #224

Merged
merged 1 commit into from
Dec 3, 2023
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
34 changes: 34 additions & 0 deletions lolly/data/unicode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

/******************************************************************************
* MODULE : json.cpp
* DESCRIPTION: Json Data Type
* COPYRIGHT : (C) 2023 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 "unicode.hpp"

namespace lolly {
namespace data {
string
unicode_get_range (int code) {
if (code <= 0x7f) return "ascii";
else if (code >= 0x80 && code <= 0x37f) return "latin";
else if (code >= 0x380 && code <= 0x3ff) return "greek";
else if (code >= 0x400 && code <= 0x4ff) return "cyrillic";
else if (code >= 0x2460 && code <= 0x24ff) return "enclosed_alphanumerics";
else if (code >= 0x3000 && code <= 0x303f) return "cjk";
else if (code >= 0x4e00 && code <= 0x9fcc) return "cjk";
else if (code >= 0xff00 && code <= 0xffef) return "cjk";
else if (code >= 0x3040 && code <= 0x309F) return "hiragana";
else if (code >= 0xac00 && code <= 0xd7af) return "hangul";
else if (code >= 0x2000 && code <= 0x23ff) return "mathsymbols";
else if (code >= 0x2900 && code <= 0x2e7f) return "mathextra";
else if (code >= 0x1d400 && code <= 0x1d7ff) return "mathletters";
else return "";
}
} // namespace data
} // namespace lolly
20 changes: 20 additions & 0 deletions lolly/data/unicode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

/******************************************************************************
* MODULE : unicode.hpp
* DESCRIPTION: Unicode support
* COPYRIGHT : (C) 2023 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>.
******************************************************************************/

#pragma once

#include "string.hpp"

namespace lolly {
namespace data {
string unicode_get_range (int code);
}
} // namespace lolly
21 changes: 21 additions & 0 deletions tests/lolly/data/unicode_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

/******************************************************************************
* MODULE : unicode_test.cpp
* DESCRIPTION: tests on unicode
* COPYRIGHT : (C) 2023 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 "a_tbox_main.cpp"
#include "lolly/data/unicode.hpp"

using lolly::data::unicode_get_range;

TEST_CASE ("unicode_get_range") {
string_eq (unicode_get_range ((int) 'a'), "ascii");
string_eq (unicode_get_range (0x2460), "enclosed_alphanumerics"); // ①
string_eq (unicode_get_range (0x24ff), "enclosed_alphanumerics"); // ⓿
}
Loading