Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
RauliL committed Feb 8, 2024
1 parent 0c0d19b commit 9d48c3a
Show file tree
Hide file tree
Showing 29 changed files with 614 additions and 643 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- name: Build
uses: ashutoshvarma/action-cmake-build@master
with:
build-dir: ${{ runner.workspace }}/build
build-type: Release
run-test: true
- uses: actions/checkout@v4
- name: Build
uses: ashutoshvarma/action-cmake-build@master
with:
build-dir: ${{ runner.workspace }}/build
build-type: Release
run-test: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.vscode
/build
/doxygen
*.o
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
CMAKE_MINIMUM_REQUIRED(VERSION 3.6)

PROJECT(
PeeloUnicode
Expand Down
6 changes: 3 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Copyright (c) 2018, peelo.net
Copyright (c) 2018-2024, peelo.net
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

Expand Down
7 changes: 2 additions & 5 deletions include/peelo/unicode/ctype.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, peelo.net
* Copyright (c) 2018-2024, peelo.net
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -24,8 +24,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PEELO_UNICODE_CTYPE_HPP_GUARD
#define PEELO_UNICODE_CTYPE_HPP_GUARD
#pragma once

#include <peelo/unicode/ctype/isalnum.hpp>
#include <peelo/unicode/ctype/isalpha.hpp>
Expand All @@ -42,5 +41,3 @@
#include <peelo/unicode/ctype/isxdigit.hpp>
#include <peelo/unicode/ctype/tolower.hpp>
#include <peelo/unicode/ctype/toupper.hpp>

#endif /* !PEELO_UNICODE_CTYPE_HPP_GUARD */
56 changes: 56 additions & 0 deletions include/peelo/unicode/ctype/_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2018-2024, peelo.net
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

#include <array>
#include <utility>

namespace peelo::unicode::ctype
{
using range = std::pair<char32_t, char32_t>;

namespace utils
{
template<std::size_t Size>
inline bool table_lookup(const std::array<range, Size>& table, char32_t c)
{
const auto size = table.size();

for (std::size_t i = 0; i < size; ++i)
{
const auto& range = table[i];

if (c >= range.first && c <= range.second)
{
return true;
}
}

return false;
}
}
}
28 changes: 10 additions & 18 deletions include/peelo/unicode/ctype/isalnum.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, peelo.net
* Copyright (c) 2018-2024, peelo.net
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -24,18 +24,20 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PEELO_UNICODE_CTYPE_ISALNUM_HPP_GUARD
#define PEELO_UNICODE_CTYPE_ISALNUM_HPP_GUARD
#pragma once

#include <peelo/unicode/ctype/_utils.hpp>

namespace peelo::unicode::ctype
{
/**
* Determines whether the given Unicode code point is alphanumeric.
*/
inline bool isalnum(char32_t c)
inline bool
isalnum(char32_t c)
{
static const char32_t alnum_table[436][2] =
{
static const std::array<range, 436> alnum_table =
{{
{ 0x0030, 0x0039 }, { 0x0041, 0x005a }, { 0x0061, 0x007a },
{ 0x00aa, 0x00aa }, { 0x00b5, 0x00b5 }, { 0x00ba, 0x00ba },
{ 0x00c0, 0x00d6 }, { 0x00d8, 0x00f6 }, { 0x00f8, 0x0241 },
Expand Down Expand Up @@ -182,18 +184,8 @@ namespace peelo::unicode::ctype
{ 0x1d78a, 0x1d7a8 }, { 0x1d7aa, 0x1d7c2 }, { 0x1d7c4, 0x1d7c9 },
{ 0x1d7ce, 0x1d7ff }, { 0x20000, 0x2a6d6 }, { 0x2f800, 0x2fa1d },
{ 0xe0100, 0xe01ef }
};

for (int i = 0; i < 436; ++i)
{
if (c >= alnum_table[i][0] && c <= alnum_table[i][1])
{
return true;
}
}
}};

return false;
return utils::table_lookup(alnum_table, c);
}
}

#endif /* !PEELO_UNICODE_CTYPE_ISALNUM_HPP_GUARD */
28 changes: 10 additions & 18 deletions include/peelo/unicode/ctype/isalpha.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, peelo.net
* Copyright (c) 2018-2024, peelo.net
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -24,18 +24,20 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PEELO_UNICODE_CTYPE_ISALPHA_HPP_GUARD
#define PEELO_UNICODE_CTYPE_ISALPHA_HPP_GUARD
#pragma once

#include <peelo/unicode/ctype/_utils.hpp>

namespace peelo::unicode::ctype
{
/**
* Determines whether the given Unicode code point is alphabetic.
*/
inline bool isalpha(char32_t c)
inline bool
isalpha(char32_t c)
{
static const char32_t alpha_table[418][2] =
{
static const std::array<range, 418> alpha_table =
{{
{ 0x0041, 0x005a }, { 0x0061, 0x007a }, { 0x00aa, 0x00aa },
{ 0x00b5, 0x00b5 }, { 0x00ba, 0x00ba }, { 0x00c0, 0x00d6 },
{ 0x00d8, 0x00f6 }, { 0x00f8, 0x0241 }, { 0x0250, 0x02c1 },
Expand Down Expand Up @@ -176,18 +178,8 @@ namespace peelo::unicode::ctype
{ 0x1d770, 0x1d788 }, { 0x1d78a, 0x1d7a8 }, { 0x1d7aa, 0x1d7c2 },
{ 0x1d7c4, 0x1d7c9 }, { 0x20000, 0x2a6d6 }, { 0x2f800, 0x2fa1d },
{ 0xe0100, 0xe01ef }
};

for (int i = 0; i < 418; ++i)
{
if (c >= alpha_table[i][0] && c <= alpha_table[i][1])
{
return true;
}
}
}};

return false;
return utils::table_lookup(alpha_table, c);
}
}

#endif /* !PEELO_UNICODE_CTYPE_ISALPHA_HPP_GUARD */
28 changes: 10 additions & 18 deletions include/peelo/unicode/ctype/isblank.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, peelo.net
* Copyright (c) 2018-2024, peelo.net
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -24,33 +24,25 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PEELO_UNICODE_CTYPE_ISBLANK_HPP_GUARD
#define PEELO_UNICODE_CTYPE_ISBLANK_HPP_GUARD
#pragma once

#include <peelo/unicode/ctype/_utils.hpp>

namespace peelo::unicode::ctype
{
/**
* Determines whether the given Unicode code point is a blank character.
*/
inline bool isblank(char32_t c)
inline bool
isblank(char32_t c)
{
static const char32_t blank_table[9][2] =
{
static const std::array<range, 9> blank_table =
{{
{ 0x0009, 0x0009 }, { 0x0020, 0x0020 }, { 0x00a0, 0x00a0 },
{ 0x1680, 0x1680 }, { 0x180e, 0x180e }, { 0x2000, 0x200a },
{ 0x202f, 0x202f }, { 0x205f, 0x205f }, { 0x3000, 0x3000 }
};

for (int i = 0; i < 9; ++i)
{
if (c >= blank_table[i][0] && c <= blank_table[i][1])
{
return true;
}
}
}};

return false;
return utils::table_lookup(blank_table, c);
}
}

#endif /* !PEELO_UNICODE_CTYPE_ISBLANK_HPP_GUARD */
28 changes: 10 additions & 18 deletions include/peelo/unicode/ctype/iscntrl.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, peelo.net
* Copyright (c) 2018-2024, peelo.net
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -24,37 +24,29 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PEELO_UNICODE_CTYPE_ISCNTRL_HPP_GUARD
#define PEELO_UNICODE_CTYPE_ISCNTRL_HPP_GUARD
#pragma once

#include <peelo/unicode/ctype/_utils.hpp>

namespace peelo::unicode::ctype
{
/**
* Determines whether the given Unicode code point is a control character.
*/
inline bool iscntrl(char32_t c)
inline bool
iscntrl(char32_t c)
{
static const char32_t cntrl_table[19][2] =
{
static const std::array<range, 19> cntrl_table =
{{
{ 0x0000, 0x001f }, { 0x007f, 0x009f }, { 0x00ad, 0x00ad },
{ 0x0600, 0x0603 }, { 0x06dd, 0x06dd }, { 0x070f, 0x070f },
{ 0x17b4, 0x17b5 }, { 0x200b, 0x200f }, { 0x202a, 0x202e },
{ 0x2060, 0x2063 }, { 0x206a, 0x206f }, { 0xd800, 0xf8ff },
{ 0xfeff, 0xfeff }, { 0xfff9, 0xfffb }, { 0x1d173, 0x1d17a },
{ 0xe0001, 0xe0001 }, { 0xe0020, 0xe007f }, { 0xf0000, 0xffffd },
{ 0x100000, 0x10fffd }
};

for (int i = 0; i < 19; ++i)
{
if (c >= cntrl_table[i][0] && c <= cntrl_table[i][1])
{
return true;
}
}
}};

return false;
return utils::table_lookup(cntrl_table, c);
}
}

#endif /* !PEELO_UNICODE_CTYPE_ISCNTRL_HPP_GUARD */
28 changes: 10 additions & 18 deletions include/peelo/unicode/ctype/isdigit.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, peelo.net
* Copyright (c) 2018-2024, peelo.net
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -24,18 +24,20 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PEELO_UNICODE_CTYPE_ISDIGIT_HPP_GUARD
#define PEELO_UNICODE_CTYPE_ISDIGIT_HPP_GUARD
#pragma once

#include <peelo/unicode/ctype/_utils.hpp>

namespace peelo::unicode::ctype
{
/**
* Determines whether the given Unicode code point is a digit.
*/
inline bool isdigit(char32_t c)
inline bool
isdigit(char32_t c)
{
static const char32_t digit_table[23][2] =
{
static const std::array<range, 23> digit_table =
{{
{ 0x0030, 0x0039 }, { 0x0660, 0x0669 }, { 0x06f0, 0x06f9 },
{ 0x0966, 0x096f }, { 0x09e6, 0x09ef }, { 0x0a66, 0x0a6f },
{ 0x0ae6, 0x0aef }, { 0x0b66, 0x0b6f }, { 0x0be6, 0x0bef },
Expand All @@ -44,18 +46,8 @@ namespace peelo::unicode::ctype
{ 0x1040, 0x1049 }, { 0x17e0, 0x17e9 }, { 0x1810, 0x1819 },
{ 0x1946, 0x194f }, { 0x19d0, 0x19d9 }, { 0xff10, 0xff19 },
{ 0x104a0, 0x104a9 }, { 0x1d7ce, 0x1d7ff }
};

for (int i = 0; i < 23; ++i)
{
if (c >= digit_table[i][0] && c <= digit_table[i][1])
{
return true;
}
}
}};

return false;
return utils::table_lookup(digit_table, c);
}
}

#endif /* !PEELO_UNICODE_CTYPE_ISDIGIT_HPP_GUARD */
Loading

0 comments on commit 9d48c3a

Please sign in to comment.