From Jason Turner

[category.ctype]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmzjb7aqv/{from.md → to.md} +117 -112
tmp/tmpmzjb7aqv/{from.md → to.md} RENAMED
@@ -2,11 +2,11 @@
2
 
3
  ``` cpp
4
  namespace std {
5
  class ctype_base {
6
  public:
7
- typedef T mask;
8
 
9
  // numeric values are for exposition only.
10
  static const mask space = 1 << 0;
11
  static const mask print = 1 << 1;
12
  static const mask cntrl = 1 << 2;
@@ -30,49 +30,42 @@ The type `mask` is a bitmask type ([[bitmask.types]]).
30
  ``` cpp
31
  namespace std {
32
  template <class charT>
33
  class ctype : public locale::facet, public ctype_base {
34
  public:
35
- typedef charT char_type;
36
 
37
  explicit ctype(size_t refs = 0);
38
 
39
  bool is(mask m, charT c) const;
40
  const charT* is(const charT* low, const charT* high, mask* vec) const;
41
- const charT* scan_is(mask m,
42
- const charT* low, const charT* high) const;
43
- const charT* scan_not(mask m,
44
- const charT* low, const charT* high) const;
45
  charT toupper(charT c) const;
46
  const charT* toupper(charT* low, const charT* high) const;
47
  charT tolower(charT c) const;
48
  const charT* tolower(charT* low, const charT* high) const;
49
 
50
  charT widen(char c) const;
51
  const char* widen(const char* low, const char* high, charT* to) const;
52
  char narrow(charT c, char dfault) const;
53
- const charT* narrow(const charT* low, const charT*, char dfault,
54
- char* to) const;
55
 
56
  static locale::id id;
57
 
58
  protected:
59
  ~ctype();
60
  virtual bool do_is(mask m, charT c) const;
61
- virtual const charT* do_is(const charT* low, const charT* high,
62
- mask* vec) const;
63
- virtual const charT* do_scan_is(mask m,
64
- const charT* low, const charT* high) const;
65
- virtual const charT* do_scan_not(mask m,
66
- const charT* low, const charT* high) const;
67
  virtual charT do_toupper(charT) const;
68
  virtual const charT* do_toupper(charT* low, const charT* high) const;
69
  virtual charT do_tolower(charT) const;
70
  virtual const charT* do_tolower(charT* low, const charT* high) const;
71
  virtual charT do_widen(char) const;
72
- virtual const char* do_widen(const char* low, const char* high,
73
- charT* dest) const;
74
  virtual char do_narrow(charT, char dfault) const;
75
  virtual const charT* do_narrow(const charT* low, const charT* high,
76
  char dfault, char* dest) const;
77
  };
78
  }
@@ -93,54 +86,54 @@ appropriate to the implementation’s native character set.
93
  bool is(mask m, charT c) const;
94
  const charT* is(const charT* low, const charT* high,
95
  mask* vec) const;
96
  ```
97
 
98
- *Returns:* `do_is(m,c)` or `do_is(low,high,vec)`
99
 
100
  ``` cpp
101
  const charT* scan_is(mask m,
102
  const charT* low, const charT* high) const;
103
  ```
104
 
105
- *Returns:* `do_scan_is(m,low,high)`
106
 
107
  ``` cpp
108
  const charT* scan_not(mask m,
109
  const charT* low, const charT* high) const;
110
  ```
111
 
112
- *Returns:* `do_scan_not(m,low,high)`
113
 
114
  ``` cpp
115
  charT toupper(charT) const;
116
  const charT* toupper(charT* low, const charT* high) const;
117
  ```
118
 
119
- *Returns:* `do_toupper(c)` or `do_toupper(low,high)`
120
 
121
  ``` cpp
122
  charT tolower(charT c) const;
123
  const charT* tolower(charT* low, const charT* high) const;
124
  ```
125
 
126
- *Returns:* `do_tolower(c)` or `do_tolower(low,high)`
127
 
128
  ``` cpp
129
  charT widen(char c) const;
130
  const char* widen(const char* low, const char* high, charT* to) const;
131
  ```
132
 
133
- *Returns:* `do_widen(c)` or `do_widen(low,high,to)`
134
 
135
  ``` cpp
136
  char narrow(charT c, char dfault) const;
137
- const charT* narrow(const charT* low, const charT*, char dfault,
138
  char* to) const;
139
  ```
140
 
141
- *Returns:* `do_narrow(c,dfault)` or `do_narrow(low,high,dfault,to)`
142
 
143
  ##### `ctype` virtual functions <a id="locale.ctype.virtuals">[[locale.ctype.virtuals]]</a>
144
 
145
  ``` cpp
146
  bool do_is(mask m, charT c) const;
@@ -149,30 +142,29 @@ const charT* do_is(const charT* low, const charT* high,
149
  ```
150
 
151
  *Effects:* Classifies a character or sequence of characters. For each
152
  argument character, identifies a value `M` of type `ctype_base::mask`.
153
  The second form identifies a value `M` of type `ctype_base::mask` for
154
- each `*p` where `(low<=p && p<high)`, and places it into `vec[p-low]`.
 
155
 
156
  *Returns:* The first form returns the result of the expression
157
  `(M & m) != 0`; i.e., `true` if the character has the characteristics
158
  specified. The second form returns `high`.
159
 
160
  ``` cpp
161
- const charT* do_scan_is(mask m,
162
- const charT* low, const charT* high) const;
163
  ```
164
 
165
  *Effects:* Locates a character in a buffer that conforms to a
166
  classification `m`.
167
 
168
- *Returns:* The smallest pointer `p` in the range `[low, high)` such that
169
- `is(m,*p)` would return `true`; otherwise, returns `high`.
170
 
171
  ``` cpp
172
- const charT* do_scan_not(mask m,
173
- const charT* low, const charT* high) const;
174
  ```
175
 
176
  *Effects:* Locates a character in a buffer that fails to conform to a
177
  classification `m`.
178
 
@@ -212,16 +204,16 @@ const char* do_widen(const char* low, const char* high,
212
  charT* dest) const;
213
  ```
214
 
215
  *Effects:* Applies the simplest reasonable transformation from a `char`
216
  value or sequence of `char` values to the corresponding `charT` value or
217
- values.[^4] The only characters for which unique transformations are
218
  required are those in the basic source character set ([[lex.charset]]).
219
 
220
  For any named `ctype` category with a `ctype <charT>` facet `ctc` and
221
  valid `ctype_base::mask` value `M`,
222
- `(ctc.is(M, c) || !is(M, do_widen(c)) )` is `true`.[^5]
223
 
224
  The second form transforms each character `*p` in the range \[`low`,
225
  `high`), placing the result in `dest[p - low]`.
226
 
227
  *Returns:* The first form returns the transformed value. The second form
@@ -266,11 +258,11 @@ no mapping is readily available. The second form returns `high`.
266
  ``` cpp
267
  namespace std {
268
  template <class charT>
269
  class ctype_byname : public ctype<charT> {
270
  public:
271
- typedef typename ctype<charT>::mask mask;
272
  explicit ctype_byname(const char*, size_t refs = 0);
273
  explicit ctype_byname(const string&, size_t refs = 0);
274
  protected:
275
  ~ctype_byname();
276
  };
@@ -279,14 +271,14 @@ namespace std {
279
 
280
  #### `ctype` specializations <a id="facet.ctype.special">[[facet.ctype.special]]</a>
281
 
282
  ``` cpp
283
  namespace std {
284
- template <> class ctype<char>
285
- : public locale::facet, public ctype_base {
286
  public:
287
- typedef char char_type;
288
 
289
  explicit ctype(const mask* tab = 0, bool del = false,
290
  size_t refs = 0);
291
 
292
  bool is(mask m, char c) const;
@@ -331,21 +323,21 @@ namespace std {
331
  };
332
  }
333
  ```
334
 
335
  A specialization `ctype<char>` is provided so that the member functions
336
- on type `char` can be implemented `inline`.[^6] The
337
  *implementation-defined* value of member `table_size` is at least 256.
338
 
339
  ##### `ctype<char>` destructor <a id="facet.ctype.char.dtor">[[facet.ctype.char.dtor]]</a>
340
 
341
  ``` cpp
342
  ~ctype();
343
  ```
344
 
345
  *Effects:* If the constructor’s first argument was nonzero, and its
346
- second argument was true, does `delete [] table()`.
347
 
348
  ##### `ctype<char>` members <a id="facet.ctype.char.members">[[facet.ctype.char.members]]</a>
349
 
350
  In the following member descriptions, for `unsigned char` values `v`
351
  where `v >= table_size`, `table()[v]` is assumed to have an
@@ -355,22 +347,23 @@ implementation-specific value (possibly different for each such value
355
  ``` cpp
356
  explicit ctype(const mask* tbl = 0, bool del = false,
357
  size_t refs = 0);
358
  ```
359
 
360
- `tbl` either 0 or an array of at least `table_size` elements.
 
361
 
362
  *Effects:* Passes its `refs` argument to its base class constructor.
363
 
364
  ``` cpp
365
  bool is(mask m, char c) const;
366
  const char* is(const char* low, const char* high,
367
  mask* vec) const;
368
  ```
369
 
370
  *Effects:* The second form, for all `*p` in the range \[`low`, `high`),
371
- assigns into `vec[p-low]` the value `table()[(unsigned char)*p]`.
372
 
373
  *Returns:* The first form returns `table()[(unsigned char)c] & m`; the
374
  second form returns `high`.
375
 
376
  ``` cpp
@@ -432,22 +425,22 @@ respectively.
432
 
433
  ``` cpp
434
  const mask* table() const noexcept;
435
  ```
436
 
437
- *Returns:* The first constructor argument, if it was non-zero, otherwise
438
  `classic_table()`.
439
 
440
  ##### `ctype<char>` static members <a id="facet.ctype.char.statics">[[facet.ctype.char.statics]]</a>
441
 
442
  ``` cpp
443
  static const mask* classic_table() noexcept;
444
  ```
445
 
446
  *Returns:* A pointer to the initial element of an array of size
447
  `table_size` which represents the classifications of characters in the
448
- "C" locale.
449
 
450
  ##### `ctype<char>` virtual functions <a id="facet.ctype.char.virtuals">[[facet.ctype.char.virtuals]]</a>
451
 
452
  ``` cpp
453
  char do_toupper(char) const;
@@ -478,46 +471,54 @@ namespace std {
478
  };
479
 
480
  template <class internT, class externT, class stateT>
481
  class codecvt : public locale::facet, public codecvt_base {
482
  public:
483
- typedef internT intern_type;
484
- typedef externT extern_type;
485
- typedef stateT state_type;
486
 
487
  explicit codecvt(size_t refs = 0);
488
 
489
- result out(stateT& state,
 
490
  const internT* from, const internT* from_end, const internT*& from_next,
491
  externT* to, externT* to_end, externT*& to_next) const;
492
- result unshift(stateT& state,
 
 
493
  externT* to, externT* to_end, externT*& to_next) const;
494
- result in(stateT& state,
 
 
495
  const externT* from, const externT* from_end, const externT*& from_next,
496
  internT* to, internT* to_end, internT*& to_next) const;
 
497
  int encoding() const noexcept;
498
  bool always_noconv() const noexcept;
499
- int length(stateT&, const externT* from, const externT* end,
500
- size_t max) const;
501
  int max_length() const noexcept;
502
 
503
  static locale::id id;
504
 
505
  protected:
506
  ~codecvt();
507
- virtual result do_out(stateT& state,
 
508
  const internT* from, const internT* from_end, const internT*& from_next,
509
  externT* to, externT* to_end, externT*& to_next) const;
510
- virtual result do_in(stateT& state,
 
511
  const externT* from, const externT* from_end, const externT*& from_next,
512
  internT* to, internT* to_end, internT*& to_next) const;
513
- virtual result do_unshift(stateT& state,
 
514
  externT* to, externT* to_end, externT*& to_next) const;
 
515
  virtual int do_encoding() const noexcept;
516
  virtual bool do_always_noconv() const noexcept;
517
- virtual int do_length(stateT&, const externT* from,
518
- const externT* end, size_t max) const;
519
  virtual int do_max_length() const noexcept;
520
  };
521
  }
522
  ```
523
 
@@ -531,103 +532,105 @@ mapped between.
531
 
532
  The specializations required in Table 
533
  [[tab:localization.category.facets]] ([[locale.category]]) convert the
534
  implementation-defined native character set.
535
  `codecvt<char, char, mbstate_t>` implements a degenerate conversion; it
536
- does not convert at all. The specialization `codecvt<char16_t,`
537
- `char, mbstate_t>` converts between the UTF-16 and UTF-8 encoding forms,
538
- and the specialization `codecvt` `<char32_t, char, mbstate_t>` converts
539
- between the UTF-32 and UTF-8 encoding forms.
540
- `codecvt<wchar_t,char,mbstate_t>` converts between the native character
541
- sets for narrow and wide characters. Specializations on `mbstate_t`
542
- perform conversion between encodings known to the library implementer.
543
- Other encodings can be converted by specializing on a user-defined
544
- `stateT` type. Objects of type `stateT` can contain any state that is
545
- useful to communicate to or from the specialized `do_in` or `do_out`
546
- members.
547
 
548
  ##### `codecvt` members <a id="locale.codecvt.members">[[locale.codecvt.members]]</a>
549
 
550
  ``` cpp
551
- result out(stateT& state,
 
552
  const internT* from, const internT* from_end, const internT*& from_next,
553
  externT* to, externT* to_end, externT*& to_next) const;
554
  ```
555
 
556
  *Returns:*
557
- `do_out(state, from, from_end, from_next, to, to_end, to_next)`
558
 
559
  ``` cpp
560
- result unshift(stateT& state,
561
- externT* to, externT* to_end, externT*& to_next) const;
562
  ```
563
 
564
- *Returns:* `do_unshift(state, to, to_end, to_next)`
565
 
566
  ``` cpp
567
- result in(stateT& state,
 
568
  const externT* from, const externT* from_end, const externT*& from_next,
569
  internT* to, internT* to_end, internT*& to_next) const;
570
  ```
571
 
572
  *Returns:*
573
- `do_in(state, from, from_end, from_next, to, to_end, to_next)`
574
 
575
  ``` cpp
576
  int encoding() const noexcept;
577
  ```
578
 
579
- *Returns:* `do_encoding()`
580
 
581
  ``` cpp
582
  bool always_noconv() const noexcept;
583
  ```
584
 
585
- *Returns:* `do_always_noconv()`
586
 
587
  ``` cpp
588
- int length(stateT& state, const externT* from, const externT* from_end,
589
- size_t max) const;
590
  ```
591
 
592
- *Returns:* `do_length(state, from,from_end,max)`
593
 
594
  ``` cpp
595
  int max_length() const noexcept;
596
  ```
597
 
598
- *Returns:* `do_max_length()`
599
 
600
  ##### `codecvt` virtual functions <a id="locale.codecvt.virtuals">[[locale.codecvt.virtuals]]</a>
601
 
602
  ``` cpp
603
- result do_out(stateT& state,
 
604
  const internT* from, const internT* from_end, const internT*& from_next,
605
  externT* to, externT* to_end, externT*& to_next) const;
606
 
607
- result do_in(stateT& state,
 
608
  const externT* from, const externT* from_end, const externT*& from_next,
609
  internT* to, internT* to_end, internT*& to_next) const;
610
  ```
611
 
612
- *Preconditions:* `(from<=from_end && to<=to_end)` well-defined and
613
  `true`; `state` initialized, if at the beginning of a sequence, or else
614
  equal to the result of converting the preceding characters in the
615
  sequence.
616
 
617
- *Effects:* Translates characters in the source range `[from,from_end)`,
618
- placing the results in sequential positions starting at destination
619
- `to`. Converts no more than `(from_end-from)` source elements, and
620
- stores no more than `(to_end-to)` destination elements.
621
 
622
  Stops if it encounters a character it cannot convert. It always leaves
623
  the `from_next` and `to_next` pointers pointing one beyond the last
624
  element successfully converted. If returns `noconv`, `internT` and
625
  `externT` are the same type and the converted sequence is identical to
626
- the input sequence `[from, from_next)`. `to_next` is set equal to `to`,
627
- the value of `state` is unchanged, and there are no changes to the
628
- values in `[to, to_end)`.
629
 
630
  A `codecvt` facet that is used by `basic_filebuf` ([[file.streams]])
631
  shall have the property that if
632
 
633
  ``` cpp
@@ -650,105 +653,107 @@ would return `ok`, where `to != to_end`, then
650
 
651
  ``` cpp
652
  do_in(state, from, from_end, from_next, to, to + 1, to_next)
653
  ```
654
 
655
- shall also return `ok`.[^7] As a result of operations on `state`, it can
656
- return `ok` or `partial` and set `from_next == from` and
657
- `to_next != to`.
658
 
659
- *Remarks:* Its operations on `state` are unspecified. This argument can
660
- be used, for example, to maintain shift state, to specify conversion
661
- options (such as count only), or to identify a cache of seek offsets.
 
 
 
 
 
 
662
 
663
  *Returns:* An enumeration value, as summarized in
664
  Table  [[tab:localization.convert.result.values.out.in]].
665
 
666
  **Table: `do_in/do_out` result values** <a id="tab:localization.convert.result.values.out.in">[tab:localization.convert.result.values.out.in]</a>
667
 
668
  | Value | Meaning |
669
  | --------- | ------------------------------------------------------------------------------------------------ |
670
  | `ok` | completed the conversion |
671
  | `partial` | not all source characters converted |
672
- | `error` | encountered a character in `[from,from_end)` that it could not convert |
673
  | `noconv` | `internT` and `externT` are the same type, and input sequence is identical to converted sequence |
674
 
675
 
676
- A return value of `partial`, if `(from_next==from_end)`, indicates that
677
- either the destination sequence has not absorbed all the available
678
  destination elements, or that additional source elements are needed
679
  before another destination element can be produced.
680
 
681
  ``` cpp
682
- result do_unshift(stateT& state,
683
- externT* to, externT* to_end, externT*& to_next) const;
684
  ```
685
 
686
- *Requires:* `(to <= to_end)` well defined and true; state initialized,
687
  if at the beginning of a sequence, or else equal to the result of
688
  converting the preceding characters in the sequence.
689
 
690
  *Effects:* Places characters starting at `to` that should be appended to
691
- terminate a sequence when the current `stateT` is given by `state`.[^8]
692
  Stores no more than `(to_end - to)` destination elements, and leaves the
693
  `to_next` pointer pointing one beyond the last element successfully
694
  stored.
695
 
696
  *Returns:* An enumeration value, as summarized in
697
  Table  [[tab:localization.convert.result.values.unshift]].
698
 
699
  **Table: `do_unshift` result values** <a id="tab:localization.convert.result.values.unshift">[tab:localization.convert.result.values.unshift]</a>
700
 
701
  | Value | Meaning |
702
- | --------- | ------------------------------------------------------------------------------------------------------------------ |
703
  | `ok` | completed the sequence |
704
  | `partial` | space for more than `to_end - to` destination elements was needed to terminate a sequence given the value of `state` |
705
  | `error` | an unspecified error has occurred |
706
  | `noconv` | no termination is needed for this `state_type` |
707
 
708
  ``` cpp
709
  int do_encoding() const noexcept;
710
  ```
711
 
712
- *Returns:* -1 if the encoding of the `externT` sequence is
713
  state-dependent; else the constant number of `externT` characters needed
714
- to produce an internal character; or 0 if this number is not a
715
- constant.[^9]
716
 
717
  ``` cpp
718
  bool do_always_noconv() const noexcept;
719
  ```
720
 
721
  *Returns:* `true` if `do_in()` and `do_out()` return `noconv` for all
722
  valid argument values. `codecvt<char, char, mbstate_t>` returns `true`.
723
 
724
  ``` cpp
725
- int do_length(stateT& state, const externT* from, const externT* from_end,
726
- size_t max) const;
727
  ```
728
 
729
- *Preconditions:* `(from<=from_end)` well-defined and `true`; `state`
730
  initialized, if at the beginning of a sequence, or else equal to the
731
  result of converting the preceding characters in the sequence.
732
 
733
  *Effects:* The effect on the `state` argument is “as if” it called
734
  `do_in(state, from, from_end, from, to, to+max, to)` for `to` pointing
735
  to a buffer of at least `max` elements.
736
 
737
  *Returns:* `(from_next-from)` where `from_next` is the largest value in
738
- the range `[from,from_end]` such that the sequence of values in the
739
  range \[`from`, `from_next`) represents `max` or fewer valid complete
740
  characters of type `internT`. The specialization
741
  `codecvt<char, char, mbstate_t>`, returns the lesser of `max` and
742
  `(from_end-from)`.
743
 
744
  ``` cpp
745
  int do_max_length() const noexcept;
746
  ```
747
 
748
  *Returns:* The maximum value that `do_length(state, from, from_end, 1)`
749
- can return for any valid range `[from, from_end)` and `stateT` value
750
  `state`. The specialization
751
  `codecvt<char, char, mbstate_t>::do_max_length()` returns 1.
752
 
753
  #### Class template `codecvt_byname` <a id="locale.codecvt.byname">[[locale.codecvt.byname]]</a>
754
 
 
2
 
3
  ``` cpp
4
  namespace std {
5
  class ctype_base {
6
  public:
7
+ using mask = T;
8
 
9
  // numeric values are for exposition only.
10
  static const mask space = 1 << 0;
11
  static const mask print = 1 << 1;
12
  static const mask cntrl = 1 << 2;
 
30
  ``` cpp
31
  namespace std {
32
  template <class charT>
33
  class ctype : public locale::facet, public ctype_base {
34
  public:
35
+ using char_type = charT;
36
 
37
  explicit ctype(size_t refs = 0);
38
 
39
  bool is(mask m, charT c) const;
40
  const charT* is(const charT* low, const charT* high, mask* vec) const;
41
+ const charT* scan_is(mask m, const charT* low, const charT* high) const;
42
+ const charT* scan_not(mask m, const charT* low, const charT* high) const;
 
 
43
  charT toupper(charT c) const;
44
  const charT* toupper(charT* low, const charT* high) const;
45
  charT tolower(charT c) const;
46
  const charT* tolower(charT* low, const charT* high) const;
47
 
48
  charT widen(char c) const;
49
  const char* widen(const char* low, const char* high, charT* to) const;
50
  char narrow(charT c, char dfault) const;
51
+ const charT* narrow(const charT* low, const charT* high, char dfault, char* to) const;
 
52
 
53
  static locale::id id;
54
 
55
  protected:
56
  ~ctype();
57
  virtual bool do_is(mask m, charT c) const;
58
+ virtual const charT* do_is(const charT* low, const charT* high, mask* vec) const;
59
+ virtual const charT* do_scan_is(mask m, const charT* low, const charT* high) const;
60
+ virtual const charT* do_scan_not(mask m, const charT* low, const charT* high) const;
 
 
 
61
  virtual charT do_toupper(charT) const;
62
  virtual const charT* do_toupper(charT* low, const charT* high) const;
63
  virtual charT do_tolower(charT) const;
64
  virtual const charT* do_tolower(charT* low, const charT* high) const;
65
  virtual charT do_widen(char) const;
66
+ virtual const char* do_widen(const char* low, const char* high, charT* dest) const;
 
67
  virtual char do_narrow(charT, char dfault) const;
68
  virtual const charT* do_narrow(const charT* low, const charT* high,
69
  char dfault, char* dest) const;
70
  };
71
  }
 
86
  bool is(mask m, charT c) const;
87
  const charT* is(const charT* low, const charT* high,
88
  mask* vec) const;
89
  ```
90
 
91
+ *Returns:* `do_is(m, c)` or `do_is(low, high, vec)`.
92
 
93
  ``` cpp
94
  const charT* scan_is(mask m,
95
  const charT* low, const charT* high) const;
96
  ```
97
 
98
+ *Returns:* `do_scan_is(m, low, high)`.
99
 
100
  ``` cpp
101
  const charT* scan_not(mask m,
102
  const charT* low, const charT* high) const;
103
  ```
104
 
105
+ *Returns:* `do_scan_not(m, low, high)`.
106
 
107
  ``` cpp
108
  charT toupper(charT) const;
109
  const charT* toupper(charT* low, const charT* high) const;
110
  ```
111
 
112
+ *Returns:* `do_toupper(c)` or `do_toupper(low, high)`.
113
 
114
  ``` cpp
115
  charT tolower(charT c) const;
116
  const charT* tolower(charT* low, const charT* high) const;
117
  ```
118
 
119
+ *Returns:* `do_tolower(c)` or `do_tolower(low, high)`.
120
 
121
  ``` cpp
122
  charT widen(char c) const;
123
  const char* widen(const char* low, const char* high, charT* to) const;
124
  ```
125
 
126
+ *Returns:* `do_widen(c)` or `do_widen(low, high, to)`.
127
 
128
  ``` cpp
129
  char narrow(charT c, char dfault) const;
130
+ const charT* narrow(const charT* low, const charT* high, char dfault,
131
  char* to) const;
132
  ```
133
 
134
+ *Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`.
135
 
136
  ##### `ctype` virtual functions <a id="locale.ctype.virtuals">[[locale.ctype.virtuals]]</a>
137
 
138
  ``` cpp
139
  bool do_is(mask m, charT c) const;
 
142
  ```
143
 
144
  *Effects:* Classifies a character or sequence of characters. For each
145
  argument character, identifies a value `M` of type `ctype_base::mask`.
146
  The second form identifies a value `M` of type `ctype_base::mask` for
147
+ each `*p` where `(low <= p && p < high)`, and places it into
148
+ `vec[p - low]`.
149
 
150
  *Returns:* The first form returns the result of the expression
151
  `(M & m) != 0`; i.e., `true` if the character has the characteristics
152
  specified. The second form returns `high`.
153
 
154
  ``` cpp
155
+ const charT* do_scan_is(mask m, const charT* low, const charT* high) const;
 
156
  ```
157
 
158
  *Effects:* Locates a character in a buffer that conforms to a
159
  classification `m`.
160
 
161
+ *Returns:* The smallest pointer `p` in the range \[`low`, `high`) such
162
+ that `is(m, *p)` would return `true`; otherwise, returns `high`.
163
 
164
  ``` cpp
165
+ const charT* do_scan_not(mask m, const charT* low, const charT* high) const;
 
166
  ```
167
 
168
  *Effects:* Locates a character in a buffer that fails to conform to a
169
  classification `m`.
170
 
 
204
  charT* dest) const;
205
  ```
206
 
207
  *Effects:* Applies the simplest reasonable transformation from a `char`
208
  value or sequence of `char` values to the corresponding `charT` value or
209
+ values.[^5] The only characters for which unique transformations are
210
  required are those in the basic source character set ([[lex.charset]]).
211
 
212
  For any named `ctype` category with a `ctype <charT>` facet `ctc` and
213
  valid `ctype_base::mask` value `M`,
214
+ `(ctc.is(M, c) || !is(M, do_widen(c)) )` is `true`.[^6]
215
 
216
  The second form transforms each character `*p` in the range \[`low`,
217
  `high`), placing the result in `dest[p - low]`.
218
 
219
  *Returns:* The first form returns the transformed value. The second form
 
258
  ``` cpp
259
  namespace std {
260
  template <class charT>
261
  class ctype_byname : public ctype<charT> {
262
  public:
263
+ using mask = typename ctype<charT>::mask;
264
  explicit ctype_byname(const char*, size_t refs = 0);
265
  explicit ctype_byname(const string&, size_t refs = 0);
266
  protected:
267
  ~ctype_byname();
268
  };
 
271
 
272
  #### `ctype` specializations <a id="facet.ctype.special">[[facet.ctype.special]]</a>
273
 
274
  ``` cpp
275
  namespace std {
276
+ template <>
277
+ class ctype<char> : public locale::facet, public ctype_base {
278
  public:
279
+ using char_type = char;
280
 
281
  explicit ctype(const mask* tab = 0, bool del = false,
282
  size_t refs = 0);
283
 
284
  bool is(mask m, char c) const;
 
323
  };
324
  }
325
  ```
326
 
327
  A specialization `ctype<char>` is provided so that the member functions
328
+ on type `char` can be implemented `inline`.[^7] The
329
  *implementation-defined* value of member `table_size` is at least 256.
330
 
331
  ##### `ctype<char>` destructor <a id="facet.ctype.char.dtor">[[facet.ctype.char.dtor]]</a>
332
 
333
  ``` cpp
334
  ~ctype();
335
  ```
336
 
337
  *Effects:* If the constructor’s first argument was nonzero, and its
338
+ second argument was `true`, does `delete [] table()`.
339
 
340
  ##### `ctype<char>` members <a id="facet.ctype.char.members">[[facet.ctype.char.members]]</a>
341
 
342
  In the following member descriptions, for `unsigned char` values `v`
343
  where `v >= table_size`, `table()[v]` is assumed to have an
 
347
  ``` cpp
348
  explicit ctype(const mask* tbl = 0, bool del = false,
349
  size_t refs = 0);
350
  ```
351
 
352
+ *Requires:* `tbl` either 0 or an array of at least `table_size`
353
+ elements.
354
 
355
  *Effects:* Passes its `refs` argument to its base class constructor.
356
 
357
  ``` cpp
358
  bool is(mask m, char c) const;
359
  const char* is(const char* low, const char* high,
360
  mask* vec) const;
361
  ```
362
 
363
  *Effects:* The second form, for all `*p` in the range \[`low`, `high`),
364
+ assigns into `vec[p - low]` the value `table()[(unsigned char)*p]`.
365
 
366
  *Returns:* The first form returns `table()[(unsigned char)c] & m`; the
367
  second form returns `high`.
368
 
369
  ``` cpp
 
425
 
426
  ``` cpp
427
  const mask* table() const noexcept;
428
  ```
429
 
430
+ *Returns:* The first constructor argument, if it was nonzero, otherwise
431
  `classic_table()`.
432
 
433
  ##### `ctype<char>` static members <a id="facet.ctype.char.statics">[[facet.ctype.char.statics]]</a>
434
 
435
  ``` cpp
436
  static const mask* classic_table() noexcept;
437
  ```
438
 
439
  *Returns:* A pointer to the initial element of an array of size
440
  `table_size` which represents the classifications of characters in the
441
+ `"C"` locale.
442
 
443
  ##### `ctype<char>` virtual functions <a id="facet.ctype.char.virtuals">[[facet.ctype.char.virtuals]]</a>
444
 
445
  ``` cpp
446
  char do_toupper(char) const;
 
471
  };
472
 
473
  template <class internT, class externT, class stateT>
474
  class codecvt : public locale::facet, public codecvt_base {
475
  public:
476
+ using intern_type = internT;
477
+ using extern_type = externT;
478
+ using state_type = stateT;
479
 
480
  explicit codecvt(size_t refs = 0);
481
 
482
+ result out(
483
+ stateT& state,
484
  const internT* from, const internT* from_end, const internT*& from_next,
485
  externT* to, externT* to_end, externT*& to_next) const;
486
+
487
+ result unshift(
488
+ stateT& state,
489
  externT* to, externT* to_end, externT*& to_next) const;
490
+
491
+ result in(
492
+ stateT& state,
493
  const externT* from, const externT* from_end, const externT*& from_next,
494
  internT* to, internT* to_end, internT*& to_next) const;
495
+
496
  int encoding() const noexcept;
497
  bool always_noconv() const noexcept;
498
+ int length(stateT&, const externT* from, const externT* end, size_t max) const;
 
499
  int max_length() const noexcept;
500
 
501
  static locale::id id;
502
 
503
  protected:
504
  ~codecvt();
505
+ virtual result do_out(
506
+ stateT& state,
507
  const internT* from, const internT* from_end, const internT*& from_next,
508
  externT* to, externT* to_end, externT*& to_next) const;
509
+ virtual result do_in(
510
+ stateT& state,
511
  const externT* from, const externT* from_end, const externT*& from_next,
512
  internT* to, internT* to_end, internT*& to_next) const;
513
+ virtual result do_unshift(
514
+ stateT& state,
515
  externT* to, externT* to_end, externT*& to_next) const;
516
+
517
  virtual int do_encoding() const noexcept;
518
  virtual bool do_always_noconv() const noexcept;
519
+ virtual int do_length(stateT&, const externT* from, const externT* end, size_t max) const;
 
520
  virtual int do_max_length() const noexcept;
521
  };
522
  }
523
  ```
524
 
 
532
 
533
  The specializations required in Table 
534
  [[tab:localization.category.facets]] ([[locale.category]]) convert the
535
  implementation-defined native character set.
536
  `codecvt<char, char, mbstate_t>` implements a degenerate conversion; it
537
+ does not convert at all. The specialization
538
+ `codecvt<char16_t, char, mbstate_t>` converts between the UTF-16 and
539
+ UTF-8 encoding forms, and the specialization `codecvt`
540
+ `<char32_t, char, mbstate_t>` converts between the UTF-32 and UTF-8
541
+ encoding forms. `codecvt<wchar_t, char, mbstate_t>` converts between the
542
+ native character sets for narrow and wide characters. Specializations on
543
+ `mbstate_t` perform conversion between encodings known to the library
544
+ implementer. Other encodings can be converted by specializing on a
545
+ user-defined `stateT` type. Objects of type `stateT` can contain any
546
+ state that is useful to communicate to or from the specialized `do_in`
547
+ or `do_out` members.
548
 
549
  ##### `codecvt` members <a id="locale.codecvt.members">[[locale.codecvt.members]]</a>
550
 
551
  ``` cpp
552
+ result out(
553
+ stateT& state,
554
  const internT* from, const internT* from_end, const internT*& from_next,
555
  externT* to, externT* to_end, externT*& to_next) const;
556
  ```
557
 
558
  *Returns:*
559
+ `do_out(state, from, from_end, from_next, to, to_end, to_next)`.
560
 
561
  ``` cpp
562
+ result unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
 
563
  ```
564
 
565
+ *Returns:* `do_unshift(state, to, to_end, to_next)`.
566
 
567
  ``` cpp
568
+ result in(
569
+ stateT& state,
570
  const externT* from, const externT* from_end, const externT*& from_next,
571
  internT* to, internT* to_end, internT*& to_next) const;
572
  ```
573
 
574
  *Returns:*
575
+ `do_in(state, from, from_end, from_next, to, to_end, to_next)`.
576
 
577
  ``` cpp
578
  int encoding() const noexcept;
579
  ```
580
 
581
+ *Returns:* `do_encoding()`.
582
 
583
  ``` cpp
584
  bool always_noconv() const noexcept;
585
  ```
586
 
587
+ *Returns:* `do_always_noconv()`.
588
 
589
  ``` cpp
590
+ int length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
 
591
  ```
592
 
593
+ *Returns:* `do_length(state, from, from_end, max)`.
594
 
595
  ``` cpp
596
  int max_length() const noexcept;
597
  ```
598
 
599
+ *Returns:* `do_max_length()`.
600
 
601
  ##### `codecvt` virtual functions <a id="locale.codecvt.virtuals">[[locale.codecvt.virtuals]]</a>
602
 
603
  ``` cpp
604
+ result do_out(
605
+ stateT& state,
606
  const internT* from, const internT* from_end, const internT*& from_next,
607
  externT* to, externT* to_end, externT*& to_next) const;
608
 
609
+ result do_in(
610
+ stateT& state,
611
  const externT* from, const externT* from_end, const externT*& from_next,
612
  internT* to, internT* to_end, internT*& to_next) const;
613
  ```
614
 
615
+ *Requires:* `(from <= from_end && to <= to_end)` well-defined and
616
  `true`; `state` initialized, if at the beginning of a sequence, or else
617
  equal to the result of converting the preceding characters in the
618
  sequence.
619
 
620
+ *Effects:* Translates characters in the source range \[`from`,
621
+ `from_end`), placing the results in sequential positions starting at
622
+ destination `to`. Converts no more than `(from_end - from)` source
623
+ elements, and stores no more than `(to_end - to)` destination elements.
624
 
625
  Stops if it encounters a character it cannot convert. It always leaves
626
  the `from_next` and `to_next` pointers pointing one beyond the last
627
  element successfully converted. If returns `noconv`, `internT` and
628
  `externT` are the same type and the converted sequence is identical to
629
+ the input sequence \[`from`, `from``next`). `to_next` is set equal to
630
+ `to`, the value of `state` is unchanged, and there are no changes to the
631
+ values in \[`to`, `to_end`).
632
 
633
  A `codecvt` facet that is used by `basic_filebuf` ([[file.streams]])
634
  shall have the property that if
635
 
636
  ``` cpp
 
653
 
654
  ``` cpp
655
  do_in(state, from, from_end, from_next, to, to + 1, to_next)
656
  ```
657
 
658
+ shall also return `ok`.[^8]
 
 
659
 
660
+ [*Note 1*: As a result of operations on `state`, it can return `ok` or
661
+ `partial` and set `from_next == from` and
662
+ `to_next != to`. *end note*]
663
+
664
+ *Remarks:* Its operations on `state` are unspecified.
665
+
666
+ [*Note 2*: This argument can be used, for example, to maintain shift
667
+ state, to specify conversion options (such as count only), or to
668
+ identify a cache of seek offsets. — *end note*]
669
 
670
  *Returns:* An enumeration value, as summarized in
671
  Table  [[tab:localization.convert.result.values.out.in]].
672
 
673
  **Table: `do_in/do_out` result values** <a id="tab:localization.convert.result.values.out.in">[tab:localization.convert.result.values.out.in]</a>
674
 
675
  | Value | Meaning |
676
  | --------- | ------------------------------------------------------------------------------------------------ |
677
  | `ok` | completed the conversion |
678
  | `partial` | not all source characters converted |
679
+ | `error` | encountered a character in {[}`from`, `from_end`{)} that it could not convert |
680
  | `noconv` | `internT` and `externT` are the same type, and input sequence is identical to converted sequence |
681
 
682
 
683
+ A return value of `partial`, if `(from_next == from_end)`, indicates
684
+ that either the destination sequence has not absorbed all the available
685
  destination elements, or that additional source elements are needed
686
  before another destination element can be produced.
687
 
688
  ``` cpp
689
+ result do_unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
 
690
  ```
691
 
692
+ *Requires:* `(to <= to_end)` well defined and `true`; state initialized,
693
  if at the beginning of a sequence, or else equal to the result of
694
  converting the preceding characters in the sequence.
695
 
696
  *Effects:* Places characters starting at `to` that should be appended to
697
+ terminate a sequence when the current `stateT` is given by `state`.[^9]
698
  Stores no more than `(to_end - to)` destination elements, and leaves the
699
  `to_next` pointer pointing one beyond the last element successfully
700
  stored.
701
 
702
  *Returns:* An enumeration value, as summarized in
703
  Table  [[tab:localization.convert.result.values.unshift]].
704
 
705
  **Table: `do_unshift` result values** <a id="tab:localization.convert.result.values.unshift">[tab:localization.convert.result.values.unshift]</a>
706
 
707
  | Value | Meaning |
708
+ | --------- | -------------------------------------------------------------------------------------------------------------------- |
709
  | `ok` | completed the sequence |
710
  | `partial` | space for more than `to_end - to` destination elements was needed to terminate a sequence given the value of `state` |
711
  | `error` | an unspecified error has occurred |
712
  | `noconv` | no termination is needed for this `state_type` |
713
 
714
  ``` cpp
715
  int do_encoding() const noexcept;
716
  ```
717
 
718
+ *Returns:* `-1` if the encoding of the `externT` sequence is
719
  state-dependent; else the constant number of `externT` characters needed
720
+ to produce an internal character; or `0` if this number is not a
721
+ constant.[^10]
722
 
723
  ``` cpp
724
  bool do_always_noconv() const noexcept;
725
  ```
726
 
727
  *Returns:* `true` if `do_in()` and `do_out()` return `noconv` for all
728
  valid argument values. `codecvt<char, char, mbstate_t>` returns `true`.
729
 
730
  ``` cpp
731
+ int do_length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
 
732
  ```
733
 
734
+ *Requires:* `(from <= from_end)` well-defined and `true`; `state`
735
  initialized, if at the beginning of a sequence, or else equal to the
736
  result of converting the preceding characters in the sequence.
737
 
738
  *Effects:* The effect on the `state` argument is “as if” it called
739
  `do_in(state, from, from_end, from, to, to+max, to)` for `to` pointing
740
  to a buffer of at least `max` elements.
741
 
742
  *Returns:* `(from_next-from)` where `from_next` is the largest value in
743
+ the range \[`from`, `from_end`\] such that the sequence of values in the
744
  range \[`from`, `from_next`) represents `max` or fewer valid complete
745
  characters of type `internT`. The specialization
746
  `codecvt<char, char, mbstate_t>`, returns the lesser of `max` and
747
  `(from_end-from)`.
748
 
749
  ``` cpp
750
  int do_max_length() const noexcept;
751
  ```
752
 
753
  *Returns:* The maximum value that `do_length(state, from, from_end, 1)`
754
+ can return for any valid range \[`from`, `from_end`) and `stateT` value
755
  `state`. The specialization
756
  `codecvt<char, char, mbstate_t>::do_max_length()` returns 1.
757
 
758
  #### Class template `codecvt_byname` <a id="locale.codecvt.byname">[[locale.codecvt.byname]]</a>
759