9#ifndef FORTRAN_EVALUATE_CHARACTER_H_
10#define FORTRAN_EVALUATE_CHARACTER_H_
12#include "flang/Evaluate/type.h"
21 using Character = Scalar<Type<TypeCategory::Character, KIND>>;
22 using CharT =
typename Character::value_type;
27 static Character CHAR(std::uint64_t code) {
28 return Character{{
static_cast<CharT
>(code)}};
33 static std::int64_t ICHAR(
const Character &c) {
34 CHECK(c.length() == 1);
36 return static_cast<common::HostUnsignedIntType<(8 * KIND)
>>(c[0]);
39 static Character NEW_LINE() {
return Character{{NewLine()}}; }
41 static Character ADJUSTL(
const Character &str) {
42 auto pos{str.find_first_not_of(Space())};
43 if (pos != Character::npos && pos != 0) {
44 return Character{str.substr(pos) + Character(pos, Space())};
50 static Character ADJUSTR(
const Character &str) {
51 auto pos{str.find_last_not_of(Space())};
52 if (pos != Character::npos && pos != str.length() - 1) {
53 auto delta{str.length() - 1 - pos};
54 return Character{Character(delta, Space()) + str.substr(0, pos + 1)};
60 static ConstantSubscript INDEX(
61 const Character &str,
const Character &substr,
bool back =
false) {
62 auto pos{back ? str.rfind(substr) : str.find(substr)};
63 return static_cast<ConstantSubscript
>(pos == str.npos ? 0 : pos + 1);
66 static ConstantSubscript SCAN(
67 const Character &str,
const Character &set,
bool back =
false) {
68 auto pos{back ? str.find_last_of(set) : str.find_first_of(set)};
69 return static_cast<ConstantSubscript
>(pos == str.npos ? 0 : pos + 1);
72 static ConstantSubscript VERIFY(
73 const Character &str,
const Character &set,
bool back =
false) {
74 auto pos{back ? str.find_last_not_of(set) : str.find_first_not_of(set)};
75 return static_cast<ConstantSubscript
>(pos == str.npos ? 0 : pos + 1);
80 static Character Resize(
const Character &str, std::size_t newLength) {
81 auto oldLength{str.length()};
82 if (newLength > oldLength) {
83 return str + Character(newLength - oldLength, Space());
85 return str.substr(0, newLength);
89 static ConstantSubscript LEN_TRIM(
const Character &str) {
92 if (str[j - 1] !=
' ') {
96 return static_cast<ConstantSubscript
>(j);
99 static Character REPEAT(
const Character &str, ConstantSubscript ncopies) {
101 if (!str.empty() && ncopies > 0) {
102 result.reserve(ncopies * str.size());
103 while (ncopies-- > 0) {
110 static Character TRIM(
const Character &str) {
111 return str.substr(0, LEN_TRIM(str));
116 static constexpr CharT Space() {
return 0x20; }
117 static constexpr CharT NewLine() {
return 0x0a; }
Definition: character.h:20