libbio
Loading...
Searching...
No Matches
NormalizeTypeName.h
Go to the documentation of this file.
1/*
2 * This file is a part of the Biology project by eons LLC.
3 * Biology (aka Develop Biology) is a framework for approaching software
4 * development from a natural sciences perspective.
5 *
6 * Copyright (C) 2024 Séon O'Shannon & eons LLC
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
25#include <algorithm>
26#include <cctype>
27#include <cstring>
28#include <string>
29
30namespace bio {
31namespace type {
32
34{
35 bool operator()(char c) const
36 {
37 return c == '*' || c == '&';
38 }
39};
40
42{
43 ::std::string raw = name.AsStdString();
44 while (raw.rfind("::", 0) == 0)
45 {
46 raw.erase(0, 2);
47 }
48 const char* tokens[] = {
49 "class ",
50 "struct ",
51 "enum ",
52 "const ",
53 "volatile "
54 };
55 for (::std::size_t i = 0; i < sizeof(tokens) / sizeof(tokens[0]); ++i)
56 {
57 const char* token = tokens[i];
58 const ::std::size_t tokenLen = ::std::strlen(token);
59 ::std::size_t pos = 0;
60 while ((pos = raw.find(token, pos)) != ::std::string::npos)
61 {
62 raw.erase(pos, tokenLen);
63 }
64 }
65 raw.erase(
66 ::std::remove_if(raw.begin(), raw.end(), ::isspace),
67 raw.end());
68 raw.erase(
69 ::std::remove_if(raw.begin(), raw.end(), RemovePointerRefFromTypeName()),
70 raw.end());
71 if (raw.size() >= 2 && raw[raw.size() - 1] == ']' && raw[raw.size() - 2] == '>')
72 {
73 raw.erase(raw.size() - 1);
74 }
75 else if (!raw.empty() && raw[raw.size() - 1] == ']')
76 {
77 raw[raw.size() - 1] = '>';
78 }
79 return String(raw);
80}
81
82} //type namespace
83} //bio namespace
std::size_t pos
Definition CborAxis.cpp:471
Definition Pointer.h:115
Definition String.h:55
String NormalizeTypeName(const String &name)
Definition NormalizeTypeName.h:41
Definition FinalCell.h:29
Definition NormalizeTypeName.h:34
bool operator()(char c) const
Definition NormalizeTypeName.h:35