[text.encoding.members]

# 28 Text processing library [[text]](./#text)

## 28.4 Text encodings identification [[text.encoding]](text.encoding#members)

### 28.4.2 Class text_encoding [[text.encoding.class]](text.encoding.class#text.encoding.members)

#### 28.4.2.3 Members [text.encoding.members]

[ð](#lib:text_encoding,constructor)

`constexpr explicit text_encoding(string_view enc) noexcept;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5137)

*Preconditions*: 

- [(1.1)](#1.1)

  enc represents a string in the ordinary literal encoding
consisting only of elements of the basic character set ([[lex.charset]](lex.charset "5.3.1 Character sets"))[.](#1.1.sentence-1)

- [(1.2)](#1.2)

  enc.size() <= max_name_length is true[.](#1.2.sentence-1)

- [(1.3)](#1.3)

  enc.contains('\0') is false[.](#1.3.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5149)

*Postconditions*: 

- [(2.1)](#2.1)

  If there exists a primary name or alias a of a known registered character encoding such that*comp-name*(a, enc) is true,*mib_* has the value of the enumerator of id associated with that registered character encoding[.](#2.1.sentence-1)
  Otherwise, *mib_* == id​::​other is true[.](#2.1.sentence-2)

- [(2.2)](#2.2)

  enc.compare(*name_*) == 0 is true[.](#2.2.sentence-1)

[ð](#lib:text_encoding,constructor_)

`constexpr text_encoding(id i) noexcept;
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5170)

*Preconditions*: i has the value of one of the enumerators of id[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5174)

*Postconditions*: 

- [(4.1)](#4.1)

  *mib_* == i is true[.](#4.1.sentence-1)

- [(4.2)](#4.2)

  If (*mib_* == id​::​unknown || *mib_* == id​::​other) is true,strlen(*name_*) == 0 is true[.](#4.2.sentence-1)
  Otherwise,ranges​::​contains(aliases(), string_view(*name_*)) is true[.](#4.2.sentence-2)

[ð](#lib:mib,text_encoding)

`constexpr id mib() const noexcept;
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5195)

*Returns*: *mib_*[.](#5.sentence-1)

[ð](#lib:name,text_encoding)

`constexpr const char* name() const noexcept;
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5206)

*Returns*: *name_*[.](#6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5210)

*Remarks*: name() is an ntbs and
accessing elements of *name_* outside of the range name()+[0, strlen(name()) + 1) is undefined behavior[.](#7.sentence-1)

[ð](#lib:aliases,text_encoding)

`constexpr aliases_view aliases() const noexcept;
`

Let r denote an instance of aliases_view[.](#sentence-1)

If *this represents a known registered character encoding, then:

- r.front() is the primary name of the registered character encoding,
- r contains the aliases of the registered character encoding, and
- r does not contain duplicate values when compared with strcmp[.](#sentence-2)

Otherwise, r is an empty range[.](#sentence-3)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5236)

Each element in r is a non-null, non-empty ntbs encoded in the literal character encoding and
comprising only characters from the basic character set[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5241)

*Returns*: r[.](#9.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5245)

[*Note [1](#note-1)*:

The order of aliases in r is unspecified[.](#10.sentence-1)

â *end note*]

[ð](#lib:literal,text_encoding)

`static consteval text_encoding literal() noexcept;
`

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5257)

*Mandates*: CHAR_BIT == 8 is true[.](#11.sentence-1)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5261)

*Returns*: A text_encoding object representing
the ordinary character literal encoding ([[lex.charset]](lex.charset "5.3.1 Character sets"))[.](#12.sentence-1)

[ð](#lib:environment,text_encoding)

`static text_encoding environment();
`

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5273)

*Mandates*: CHAR_BIT == 8 is true[.](#13.sentence-1)

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5277)

*Returns*: A text_encoding object representing
the implementation-defined
character encoding scheme of the environment[.](#14.sentence-1)

On a POSIX implementation, this is the encoding scheme associated with
the POSIX locale denoted by the empty string ""[.](#14.sentence-2)

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5285)

[*Note [2](#note-2)*:

This function is not affected by calls to setlocale[.](#15.sentence-1)

â *end note*]

[16](#16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5290)

*Recommended practice*: Implementations should return a value that is not affected by calls to
the POSIX function setenv and
other functions which can modify the environment ([[support.runtime]](support.runtime "17.14 Other runtime support"))[.](#16.sentence-1)

[ð](#lib:environment_is,text_encoding)

`template<id i>
  static bool environment_is();
`

[17](#17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5304)

*Mandates*: CHAR_BIT == 8 is true[.](#17.sentence-1)

[18](#18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5308)

*Returns*: environment() == i[.](#18.sentence-1)

[ð](#lib:comp-name,text_encoding)

`static constexpr bool comp-name(string_view a, string_view b);
`

[19](#19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L5319)

*Returns*: true if the two strings a and b encoded in the ordinary literal encoding
are equal, ignoring, from left-to-right,

- [(19.1)](#19.1)

all elements that are not digits or letters ([[character.seq.general]](character.seq.general "16.3.3.3.4.1 General")),

- [(19.2)](#19.2)

character case, and

- [(19.3)](#19.3)

any sequence of one or more 0 characters
not immediately preceded by a numeric prefix, where
a numeric prefix is a sequence consisting of
a digit in the range [1, 9]
optionally followed by one or more elements which are not digits or letters,

and false otherwise[.](#19.sentence-1)

[*Note [3](#note-3)*:

This comparison is identical to
the âCharset Alias Matchingâ algorithm
described in the Unicode Technical Standard 22[[bib]](bibliography#bib:unicode-charmap "Bibliography")[.](#19.sentence-2)

â *end note*]

[*Example [1](#example-1)*: static_assert(*comp-name*("UTF-8", "utf8") == true);static_assert(*comp-name*("u.t.f-008", "utf8") == true);static_assert(*comp-name*("ut8", "utf8") == false);static_assert(*comp-name*("utf-80", "utf8") == false); â *end example*]
