Files
2025-10-25 03:02:53 +03:00

406 lines
10 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[re.req]
# 28 Text processing library [[text]](./#text)
## 28.6 Regular expressions library [[re]](re#req)
### 28.6.2 Requirements [re.req]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9032)
This subclause defines requirements on classes representing regular
expression traits[.](#1.sentence-1)
[*Note [1](#note-1)*:
The class templateregex_traits, defined in [[re.traits]](re.traits "28.6.6Class template regex_­traits"),
meets these requirements[.](#1.sentence-2)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9041)
The class template basic_regex, defined in[[re.regex]](re.regex "28.6.7Class template basic_­regex"), needs a set of related types and
functions to complete the definition of its semantics[.](#2.sentence-1)
These types
and functions are provided as a set of member [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4The typedef specifier[dcl.typedef]")*s* and functions
in the template parameter traits used by the basic_regex class
template[.](#2.sentence-2)
This subclause defines the semantics of these
members[.](#2.sentence-3)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9050)
To specialize class template basic_regex for a character
container CharT and its related regular
expression traits class Traits, use basic_regex<CharT, Traits>[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9055)
In the following requirements,
- [(4.1)](#4.1)
X denotes a traits class defining types and functions
for the character container type charT;
- [(4.2)](#4.2)
u is an object of type X;
- [(4.3)](#4.3)
v is an object of type const X;
- [(4.4)](#4.4)
p is a value of type const charT*;
- [(4.5)](#4.5)
I1 and I2 are input iterators ([[input.iterators]](input.iterators "24.3.5.3Input iterators"));
- [(4.6)](#4.6)
F1 and F2 are forward iterators ([[forward.iterators]](forward.iterators "24.3.5.5Forward iterators"));
- [(4.7)](#4.7)
c is a value of type const charT;
- [(4.8)](#4.8)
s is an object of type X::string_type;
- [(4.9)](#4.9)
cs is an object of type const X::string_type;
- [(4.10)](#4.10)
b is a value of type bool;
- [(4.11)](#4.11)
I is a value of type int;
- [(4.12)](#4.12)
cl is an object of type X::char_class_type; and
- [(4.13)](#4.13)
loc is an object of type X::locale_type[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9091)
A traits class X meets the regular expression traits requirements
if the following types and expressions are well-formed and have the specified
semantics[.](#5.sentence-1)
[🔗](#itemdecl:1)
`typename X::char_type
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9101)
*Result*: charT,
the character container type used in the implementation of class
template basic_regex[.](#6.sentence-1)
[🔗](#itemdecl:2)
`typename X::string_type
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9113)
*Result*: basic_string<charT>
[🔗](#itemdecl:3)
`typename X::locale_type
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9123)
*Result*: A copy constructible type
that represents the locale used by the traits class[.](#8.sentence-1)
[🔗](#itemdecl:4)
`typename X::char_class_type
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9134)
*Result*: A bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3Bitmask types"))
representing a particular character classification[.](#9.sentence-1)
[🔗](#itemdecl:5)
`X::length(p)
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9145)
*Result*: size_t
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9149)
*Returns*: The smallest i such that p[i] == 0[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9153)
*Complexity*: Linear in i[.](#12.sentence-1)
[🔗](#itemdecl:6)
`v.translate(c)
`
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9163)
*Result*: X::char_type
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9167)
*Returns*: A character such that for any character d that is to be considered equivalent to c then v.translate(c) == v.translate(d)[.](#14.sentence-1)
[🔗](#itemdecl:7)
`v.translate_nocase(c)
`
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9179)
*Result*: X::char_type
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9183)
*Returns*: For all characters C that are to be considered equivalent to c when comparisons are to be performed without regard to case,
then v.translate_nocase(c) == v.translate_nocase(C)[.](#16.sentence-1)
[🔗](#itemdecl:8)
`v.transform(F1, F2)
`
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9195)
*Result*: X::string_type
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9199)
*Returns*: A sort key for the character sequence designated by
the iterator range [F1, F2) such that
if the character sequence [G1, G2) sorts before
the character sequence [H1, H2)
then v.transform(G1, G2) < v.transform(H1, H2)[.](#18.sentence-1)
[🔗](#itemdecl:9)
`v.transform_primary(F1, F2)
`
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9213)
*Result*: X::string_type
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9219)
*Returns*: A sort key for the character sequence designated by
the iterator range [F1, F2) such that
if the character sequence [G1, G2) sorts before
the character sequence [H1, H2)
when character case is not considered
then v.transform_primary(G1, G2) < v.transform_primary(H1, H2)[.](#20.sentence-1)
[🔗](#itemdecl:10)
`v.lookup_collatename(F1, F2)
`
[21](#21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9234)
*Result*: X::string_type
[22](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9238)
*Returns*: A sequence of characters that represents the collating element
consisting of the character sequence designated by
the iterator range [F1, F2)[.](#22.sentence-1)
Returns an empty string
if the character sequence is not a valid collating element[.](#22.sentence-2)
[🔗](#itemdecl:11)
`v.lookup_classname(F1, F2, b)
`
[23](#23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9252)
*Result*: X::char_class_type
[24](#24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9256)
*Returns*: Converts the character sequence designated by the iterator range
[F1, F2) into a value of a bitmask type that can
subsequently be passed to isctype[.](#24.sentence-1)
Values returned from lookup_classname can be bitwise or'ed together;
the resulting value represents membership
in either of the corresponding character classes[.](#24.sentence-2)
If b is true, the returned bitmask is suitable for
matching characters without regard to their case[.](#24.sentence-3)
Returns 0 if the character sequence is not the name of
a character class recognized by X[.](#24.sentence-4)
The value returned shall be independent of
the case of the characters in the sequence[.](#24.sentence-5)
[🔗](#itemdecl:12)
`v.isctype(c, cl)
`
[25](#25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9278)
*Result*: bool
[26](#26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9282)
*Returns*: Returns true if character c is a member of
one of the character classes designated by cl,false otherwise[.](#26.sentence-1)
[🔗](#itemdecl:13)
`v.value(c, I)
`
[27](#27)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9294)
*Result*: int
[28](#28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9298)
*Returns*: Returns the value represented by the digit *c* in base*I* if the character *c* is a valid digit in base *I*;
otherwise returns -1[.](#28.sentence-1)
[*Note [2](#note-2)*:
The value of *I* will only be 8, 10, or 16[.](#28.sentence-2)
— *end note*]
[🔗](#itemdecl:14)
`u.imbue(loc)
`
[29](#29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9313)
*Result*: X::locale_type
[30](#30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9318)
*Effects*: Imbues u with the locale loc and
returns the previous locale used by u if any[.](#30.sentence-1)
[🔗](#itemdecl:15)
`v.getloc()
`
[31](#31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9329)
*Result*: X::locale_type
[32](#32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9333)
*Returns*: Returns the current locale used by v, if any[.](#32.sentence-1)
[33](#33)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9338)
[*Note [3](#note-3)*:
Class template regex_traits meets the requirements for a
regular expression traits class when it is specialized forchar or wchar_t[.](#33.sentence-1)
This class template is described in
the header [<regex>](re.syn#header:%3cregex%3e "28.6.3Header <regex> synopsis[re.syn]"), and is described in [[re.traits]](re.traits "28.6.6Class template regex_­traits")[.](#33.sentence-2)
— *end note*]