99
1010#include " parser/LiteralOrIri.h"
1111
12- static constexpr NormalizedChar quote{' "' };
13- static constexpr NormalizedChar at{' @' };
14- static constexpr NormalizedChar hat{' ^' };
12+ static constexpr char quote{' "' };
13+ static constexpr char at{' @' };
14+ static constexpr char hat{' ^' };
1515
1616namespace ad_utility ::triple_component {
1717// __________________________________________
18- Literal::Literal (NormalizedString content, size_t beginOfSuffix)
18+ Literal::Literal (std::string content, size_t beginOfSuffix)
1919 : content_{std::move (content)}, beginOfSuffix_{beginOfSuffix} {
2020 AD_CORRECTNESS_CHECK (content_.starts_with (quote));
2121 AD_CORRECTNESS_CHECK (beginOfSuffix_ >= 2 );
@@ -33,7 +33,7 @@ bool Literal::hasDatatype() const { return getSuffix().starts_with(hat); }
3333
3434// __________________________________________
3535NormalizedStringView Literal::getContent () const {
36- return NormalizedStringView{content_} .substr (1 , beginOfSuffix_ - 2 );
36+ return content () .substr (1 , beginOfSuffix_ - 2 );
3737}
3838
3939// __________________________________________
@@ -42,7 +42,7 @@ NormalizedStringView Literal::getDatatype() const {
4242 AD_THROW (" The literal does not have an explicit datatype." );
4343 }
4444 // We don't return the enclosing <angle brackets>
45- NormalizedStringView result = content_ ;
45+ NormalizedStringView result = content () ;
4646 result.remove_prefix (beginOfSuffix_ + 3 );
4747 result.remove_suffix (1 );
4848 return result;
@@ -53,7 +53,7 @@ NormalizedStringView Literal::getLanguageTag() const {
5353 if (!hasLanguageTag ()) {
5454 AD_THROW (" The literal does not have an explicit language tag." );
5555 }
56- return NormalizedStringView{content_} .substr (beginOfSuffix_ + 1 );
56+ return content () .substr (beginOfSuffix_ + 1 );
5757}
5858
5959// __________________________________________
@@ -80,8 +80,9 @@ Literal Literal::literalWithoutQuotes(
8080Literal Literal::literalWithNormalizedContent (
8181 NormalizedString normalizedRdfContent,
8282 std::optional<std::variant<Iri, string>> descriptor) {
83- auto quotes = asNormalizedStringViewUnsafe (" \" " );
84- auto actualContent = quotes + std::move (normalizedRdfContent) + quotes;
83+ auto quotes = " \" " sv;
84+ auto actualContent =
85+ absl::StrCat (quotes, asStringViewUnsafe (normalizedRdfContent), quotes);
8586 auto sz = actualContent.size ();
8687 auto literal = Literal{std::move (actualContent), sz};
8788 if (!descriptor.has_value ()) {
@@ -104,31 +105,34 @@ Literal Literal::literalWithNormalizedContent(
104105
105106// __________________________________________
106107void Literal::addLanguageTag (std::string_view languageTag) {
107- content_.push_back (at);
108- content_.append (RdfEscaping::normalizeLanguageTag (languageTag));
108+ AD_CORRECTNESS_CHECK (!hasDatatype () && !hasLanguageTag ());
109+ if (languageTag.starts_with (' @' )) {
110+ absl::StrAppend (&content_, languageTag);
111+ } else {
112+ absl::StrAppend (&content_, " @" sv, languageTag);
113+ }
109114}
110115
111116// __________________________________________
112117void Literal::addDatatype (const Iri& datatype) {
113- content_.append (asNormalizedStringViewUnsafe (" ^^" ));
114- content_.append (
115- asNormalizedStringViewUnsafe (datatype.toStringRepresentation ()));
118+ AD_CORRECTNESS_CHECK (!hasDatatype () && !hasLanguageTag ());
119+ absl::StrAppend (&content_, " ^^" sv, datatype.toStringRepresentation ());
116120}
117121
118122// __________________________________________
119- std::string_view Literal::toStringRepresentation () const {
120- return asStringViewUnsafe (content_);
121- }
123+ const std::string& Literal::toStringRepresentation () const { return content_; }
124+
125+ // __________________________________________
126+ std::string& Literal::toStringRepresentation () { return content_; }
122127
123128// __________________________________________
124- Literal Literal::fromStringRepresentation (std::string_view internal) {
129+ Literal Literal::fromStringRepresentation (std::string internal) {
125130 // TODO<joka921> This is a little dangerous as there might be quotes in the
126131 // IRI which might lead to unexpected results here.
127132 AD_CORRECTNESS_CHECK (internal.starts_with (' "' ));
128133 auto endIdx = internal.rfind (' "' );
129134 AD_CORRECTNESS_CHECK (endIdx > 0 );
130- return Literal{NormalizedString{asNormalizedStringViewUnsafe (internal)},
131- endIdx + 1 };
135+ return Literal{std::move (internal), endIdx + 1 };
132136}
133137
134138} // namespace ad_utility::triple_component
0 commit comments