Skip to content

Commit

Permalink
Renamed basic_text to text
Browse files Browse the repository at this point in the history
  • Loading branch information
Martinho Fernandes committed Feb 3, 2013
1 parent 81896b2 commit f2401ed
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ running `python scons.py dist` from the command line (requires Python to be inst

Here's a list of what's implemented so far:

- `basic_text`, a text class template, sometimes known as string. I'm leaving
- `text`, a text class template, sometimes known as string. I'm leaving
"string" to mean "array of code units", as it's what a `string` class often
turns out to be (and also what strings in other languages turn out to be).
This is not that. This represents text, regardless of encoding. It's a
Expand All @@ -30,7 +30,7 @@ Here's a list of what's implemented so far:
makes conversions at API boundaries simple and type-safe. See these documents
for more info on the ideas behind this class: [motivation] and [design].

- `any_text`, a type erased variant of `basic_text` for use in compiled
- `any_text`, a type erased variant of `text` for use in compiled
boundaries, or whenever templates are not appropriate/desired;

- facilities for converting between ranges of codepoints to ranges of code
Expand Down
2 changes: 1 addition & 1 deletion concepts.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Table: Requirements for `EncodingScheme`

Ouch.

## `basic_text` and `text`
## `text` and `any_text`

See http://gist.io/3166256.

Expand Down
50 changes: 25 additions & 25 deletions include/ogonek/text.h++
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace ogonek {
} // namespace detail

template <typename EncodingForm, typename Container = std::basic_string<CodeUnit<EncodingForm>>>
struct basic_text : private detail::validated<EncodingForm> {
struct text : private detail::validated<EncodingForm> {
private:
static_assert(std::is_convertible<CodeUnit<EncodingForm>, detail::ValueType<Container>>::value,
"The encoding form code units should be convertible to the container's value type");
Expand All @@ -79,41 +79,41 @@ namespace ogonek {

// -- basic
//! Empty string
basic_text() = default;
text() = default;

// Copies and moves (explicit to prevent the range construction templates from being used)
basic_text(basic_text const&) = default;
basic_text(basic_text&&) = default;
basic_text& operator=(basic_text const&) = default;
basic_text& operator=(basic_text&&) = default;
text(text const&) = default;
text(text&&) = default;
text& operator=(text const&) = default;
text& operator=(text&&) = default;

// -- codepoints
//! Construct from a null-terminated codepoint string (intended for UTF-32 literals)
basic_text(codepoint const* literal)
: basic_text(literal, throw_validation_error) {}
text(codepoint const* literal)
: text(literal, throw_validation_error) {}

//! Construct from a null-terminated codepoint string, with validation callback
template <typename ValidationPolicy>
basic_text(codepoint const* literal, ValidationPolicy)
: basic_text(boost::make_iterator_range(literal, literal + std::char_traits<codepoint>::length(literal)),
text(codepoint const* literal, ValidationPolicy)
: text(boost::make_iterator_range(literal, literal + std::char_traits<codepoint>::length(literal)),
ValidationPolicy{}) {}

//! Construct from a codepoint range
template <typename CodepointRange>
explicit basic_text(CodepointRange const& range)
: basic_text(range, throw_validation_error) {}
explicit text(CodepointRange const& range)
: text(range, throw_validation_error) {}

//! Construct from a codepoint range, with validation policy
template <typename CodepointRange, typename ValidationPolicy>
basic_text(CodepointRange const& range, ValidationPolicy)
: basic_text(direct{}, EncodingForm::encode(range, ValidationPolicy{})) {
text(CodepointRange const& range, ValidationPolicy)
: text(direct{}, EncodingForm::encode(range, ValidationPolicy{})) {
static_assert(std::is_same<detail::RangeValueType<CodepointRange>, codepoint>::value,
"Can only construct text from a range of codepoints");
}

// -- storage
//! Construct from an underlying container
explicit basic_text(Container storage) // TODO: strong guarantee!
explicit text(Container storage) // TODO: strong guarantee!
: detail::validated<EncodingForm>(storage, throw_validation_error),
storage_(std::move(storage)) {}

Expand All @@ -140,16 +140,16 @@ namespace ogonek {

private:
template <typename Range>
basic_text(direct, Range&& range)
text(direct, Range&& range)
: storage_(boost::begin(range), boost::end(range)) {}

Container storage_;
};

class utf8;
class utf16;
using posix_text = basic_text<utf8, std::string>;
using windows_text = basic_text<utf16, std::wstring>;
using posix_text = text<utf8, std::string>;
using windows_text = text<utf16, std::wstring>;
#ifdef OGONEK_WINDOWS
using native_text = windows_text;
#else
Expand All @@ -158,8 +158,8 @@ namespace ogonek {

class narrow;
class wide;
using narrow_text = basic_text<narrow, std::string>;
using wide_text = basic_text<wide, std::wstring>;
using narrow_text = text<narrow, std::string>;
using wide_text = text<wide, std::wstring>;

class any_text {
public:
Expand Down Expand Up @@ -193,7 +193,7 @@ namespace ogonek {
template <typename EncodingForm, typename Container>
class holder : public placeholder {
public:
using text_type = basic_text<EncodingForm, Container>;
using text_type = text<EncodingForm, Container>;

holder(text_type const& text) : text(text) {}
holder(text_type&& text) : text(std::move(text)) {}
Expand Down Expand Up @@ -230,19 +230,19 @@ namespace ogonek {
any_text& operator=(any_text&&) = default;

template <typename EncodingForm, typename Container>
any_text(basic_text<EncodingForm, Container> const& text)
any_text(text<EncodingForm, Container> const& text)
: handle { wheels::make_unique<holder<EncodingForm, Container>>(text) } {}
template <typename EncodingForm, typename Container>
any_text(basic_text<EncodingForm, Container>&& text)
any_text(text<EncodingForm, Container>&& text)
: handle { wheels::make_unique<holder<EncodingForm, Container>>(std::move(text)) } {}

template <typename EncodingForm, typename Container>
any_text& operator=(basic_text<EncodingForm, Container> const& text) {
any_text& operator=(text<EncodingForm, Container> const& text) {
handle = wheels::make_unique<holder<EncodingForm, Container>>(text);
return *this;
}
template <typename EncodingForm, typename Container>
any_text& operator=(basic_text<EncodingForm, Container>&& text) {
any_text& operator=(text<EncodingForm, Container>&& text) {
handle = wheels::make_unique<holder<EncodingForm, Container>>(std::move(text));
return *this;
}
Expand Down
24 changes: 12 additions & 12 deletions include/ogonek/ucd.h++
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace ogonek {
// Forward declare for text properties
template <typename Encoding, typename Container>
class basic_text;
class text;
class utf8;

template <typename T, std::size_t N>
Expand Down Expand Up @@ -455,7 +455,7 @@ namespace ogonek {
extern OGONEK_PUBLIC miscellaneous_properties const* miscellaneous_data;
extern OGONEK_PUBLIC std::size_t miscellaneous_data_size;

using text = basic_text<utf8, std::string>;
using text_type = text<utf8, std::string>;

namespace detail {
struct property_group_locator {
Expand Down Expand Up @@ -497,28 +497,28 @@ namespace ogonek {
return result;
}

inline text get_name(name_properties const* data, std::size_t data_size, codepoint u) {
inline text_type get_name(name_properties const* data, std::size_t data_size, codepoint u) {
name_properties const& p = detail::find_property_group(data, data_size, u);
if(p.variable) {
std::string name { p.name };
name.reserve(name.size() + 5);
name.replace(name.find('#'), 1, to_hex(u));
return text { std::move(name) };
return text_type { std::move(name) };
} else {
return text {{ p.name }};
return text_type {{ p.name }};
}
}
} // namespace detail
inline text get_name(codepoint u) {
inline text_type get_name(codepoint u) {
return detail::get_name(name_data, name_data_size, u);
}
inline text get_unicode1_name(codepoint u) {
inline text_type get_unicode1_name(codepoint u) {
return detail::get_name(v1name_data, v1name_data_size, u);
}
struct alias {
alias(alias_raw const& raw) : type{raw.type}, name{{raw.name}} {}
alias_type type;
text name;
text_type name;
};
inline std::vector<alias> get_aliases(codepoint u) {
auto group = detail::find_property_group(aliases_data, aliases_data_size, u);
Expand Down Expand Up @@ -729,14 +729,14 @@ namespace ogonek {
auto& prop = detail::find_property_group(script_data, script_data_size, u);
return { prop.first_script_extension, prop.first_script_extension + prop.script_extension_count };
}
inline text get_iso_comment(codepoint u) {
return text { detail::find_property_group(iso_comment_data, iso_comment_data_size, u).data };
inline text_type get_iso_comment(codepoint u) {
return text_type { detail::find_property_group(iso_comment_data, iso_comment_data_size, u).data };
}
inline hangul_syllable_type get_hangul_syllable_type(codepoint u) {
return detail::find_property_group(hangul_data, hangul_data_size, u).syllable_type;
}
inline text get_jamo_short_name(codepoint u) {
return text {{ detail::find_property_group(hangul_data, hangul_data_size, u).jamo_short_name }};
inline text_type get_jamo_short_name(codepoint u) {
return text_type {{ detail::find_property_group(hangul_data, hangul_data_size, u).jamo_short_name }};
}
inline indic_syllable_category get_indic_syllable_category(codepoint u) {
return detail::find_property_group(indic_data, indic_data_size, u).syllable_category;
Expand Down
2 changes: 1 addition & 1 deletion test/issue-00013.c++
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <ogonek/validation.h++>

TEST_CASE("issue13", "Tests for issue #13") {
using text8 = ogonek::basic_text<ogonek::utf8>;
using text8 = ogonek::text<ogonek::utf8>;

SECTION("original", "Original test, shortened") {
std::string s = u8"\u043f\u0440\u0438\u0432\u0435\u0442";
Expand Down
8 changes: 4 additions & 4 deletions test/normalization.c++
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ std::ostream& operator<<(std::ostream& os, std::u32string const& u32) {
}

TEST_CASE("decompose", "Decomposition") {
using test_text = ogonek::basic_text<ogonek::utf32>;
using test_text = ogonek::text<ogonek::utf32>;
test_text in { U"ABC\x00C5\x00F4\x1E69\x1E0B\x0323\x0071\x0307\x0323" };
test_text out { ogonek::decompose(in) };
REQUIRE(out.storage() == std::u32string { U"ABC\x0041\x030A\x006F\x0302\x0073\x0323\x0307\x0064\x0307\x0323\x0071\x0307\x0323" });
}

TEST_CASE("canonical ordering", "Decomposition + canonical ordering") {
using test_text = ogonek::basic_text<ogonek::utf32>;
using test_text = ogonek::text<ogonek::utf32>;
test_text in { U"\x1E69\x1E0B\x0323\x0071\x0307\x0323" };
test_text out { ogonek::decompose_ordered(in) };
REQUIRE(out.storage() == std::u32string { U"\x0073\x0323\x0307\x0064\x0323\x0307\x0071\x0323\x0307" });
}

TEST_CASE("nfd", "Normalization Form D") {
using test_text = ogonek::basic_text<ogonek::utf32>;
using test_text = ogonek::text<ogonek::utf32>;
std::u32string input = U"\x1E69\x1E0B\x0323\x0071\x0307\x0323";
std::u32string normalized = U"\x0073\x0323\x0307\x0064\x0323\x0307\x0071\x0323\x0307";

Expand All @@ -52,7 +52,7 @@ TEST_CASE("nfd", "Normalization Form D") {
}

TEST_CASE("nfc", "Normalization Form C") {
using test_text = ogonek::basic_text<ogonek::utf32>;
using test_text = ogonek::text<ogonek::utf32>;
SECTION("test1", "") {
std::u32string input = U"\x1E69\x1E0B\x0323\x0071\x0307\x0323";
std::u32string normalized = U"\x1E69\x1E0D\x0307\x0071\x0323\x0307";
Expand Down
8 changes: 4 additions & 4 deletions test/text.c++
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include <catch.h++>

TEST_CASE("text", "text tests") {
using text8 = ogonek::basic_text<ogonek::utf8>;
using text16 = ogonek::basic_text<ogonek::utf16>;
using text32 = ogonek::basic_text<ogonek::utf32>;
using text_ascii = ogonek::basic_text<ogonek::ascii>;
using text8 = ogonek::text<ogonek::utf8>;
using text16 = ogonek::text<ogonek::utf16>;
using text32 = ogonek::text<ogonek::utf32>;
using text_ascii = ogonek::text<ogonek::ascii>;

SECTION("general", "General test") {
// construct UTF-8 text from a UTF-32 string literal
Expand Down

0 comments on commit f2401ed

Please sign in to comment.