23 using Character = Scalar<Type<TypeCategory::Character>>;
24 using CharT = char32_t;
29 static Character CHAR(
int kind, std::uint64_t code) {
30 return Character{kind, 1,
static_cast<CharT
>(code)};
35 static std::int64_t ICHAR(
const Character &c) {
36 CHECK(c.length() == 1);
42 static Character NEW_LINE(
int kind) {
return Character{kind, 1, NewLine()}; }
44 static Character ADJUSTL(
const Character &str) {
45 const int kind{str.kind()};
46 auto pos{str.find_first_not_of(Space())};
47 if (pos != Character::npos && pos != 0) {
48 return Character{str.substr(pos) + Character{kind, pos, Space()}};
54 static Character ADJUSTR(
const Character &str) {
55 const int kind{str.kind()};
56 auto pos{str.find_last_not_of(Space())};
57 if (pos != Character::npos && pos != str.length() - 1) {
58 auto delta{str.length() - 1 - pos};
60 Character{kind, delta, Space()} + str.substr(0, pos + 1)};
66 static ConstantSubscript INDEX(
67 const Character &str,
const Character &substr,
bool back =
false) {
68 auto pos{back ? str.rfind(substr) : str.find(substr)};
69 return static_cast<ConstantSubscript
>(pos == str.npos ? 0 : pos + 1);
72 static ConstantSubscript SCAN(
73 const Character &str,
const Character &set,
bool back =
false) {
74 auto pos{back ? str.find_last_of(set) : str.find_first_of(set)};
75 return static_cast<ConstantSubscript
>(pos == str.npos ? 0 : pos + 1);
78 static ConstantSubscript VERIFY(
79 const Character &str,
const Character &set,
bool back =
false) {
80 auto pos{back ? str.find_last_not_of(set) : str.find_first_not_of(set)};
81 return static_cast<ConstantSubscript
>(pos == str.npos ? 0 : pos + 1);
86 static Character Resize(
const Character &str, std::size_t newLength) {
87 const int kind{str.kind()};
88 auto oldLength{str.length()};
89 if (newLength > oldLength) {
90 return str + Character{kind, newLength - oldLength, Space()};
92 return str.substr(0, newLength);
96 static ConstantSubscript LEN_TRIM(
const Character &str) {
99 if (str[j - 1] !=
' ') {
103 return static_cast<ConstantSubscript
>(j);
106 static Character REPEAT(
const Character &str, ConstantSubscript ncopies) {
107 const int kind{str.kind()};
108 Character result{Character::Zero(kind)};
109 if (!str.empty() && ncopies > 0) {
110 result.reserve(ncopies * str.size());
111 while (ncopies-- > 0) {
118 static Character TRIM(
const Character &str) {
119 return str.substr(0, LEN_TRIM(str));
124 static constexpr CharT Space() {
return 0x20; }
125 static constexpr CharT NewLine() {
return 0x0a; }