MTMS main
Modern Turing Machine Simulator
Loading...
Searching...
No Matches
string.cpp
Go to the documentation of this file.
1
11#include "string.hpp"
12
13#include <algorithm>
14
20String::String(std::string_view str)
21{
22 this->symbols_.reserve(str.size());
23 for (const auto &ch : str)
24 {
25 this->symbols_.emplace_back(ch);
26 }
27}
28
34std::string String::get_str() const noexcept(false)
35{
36 std::string result;
37 result.reserve(this->symbols_.size());
38
39 for (const auto &sym : this->symbols_)
40 {
41 result.push_back(sym.get_char());
42 }
43
44 return result;
45}
46
52bool String::is_valid_for(const Alphabet &alphabet) const noexcept
53{
54 return std::ranges::all_of(this->symbols_, [&alphabet](const Symbol &s) {
55 return alphabet.contains(s);
56 });
57}
Represents the formal alphabet ( or ) of a Turing Machine.
Definition alphabet.hpp:27
std::vector< Symbol > symbols_
The finite sequence of symbols forming the string.
Definition string.hpp:101
std::string get_str() const noexcept(false)
Reconstructs a standard std::string representation from the underlying symbols.
Definition string.cpp:34
bool is_valid_for(const Alphabet &alphabet) const noexcept
Validates if all symbols within this string belong to a specific formal Alphabet.
Definition string.cpp:52
String() noexcept=default
Default constructor.
Represents a single symbol on the Turing Machine's tape.
Definition symbol.hpp:30
String class representing a formal string (sequence of symbols) over an alphabet.