Arcane  v3.15.3.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
StringView.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* StringView.cc (C) 2000-2025 */
9/* */
10/* Vue sur une chaîne de caractères UTF-8. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/base/StringView.h"
15
16#include <iostream>
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Arccore
22{
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
28writeBytes(std::ostream& o) const
29{
30 o.write((const char*)m_v.data(),m_v.size());
31}
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
37subView(Int64 pos) const
38{
39 return subView(pos, length() - pos);
40}
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
46subView(Int64 pos, Int64 len) const
47{
48 if (pos < 0)
49 pos = 0;
50 return { m_v.subspan(pos, len) };
51}
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
56std::ostream&
57operator<<(std::ostream& o,const StringView& str)
58{
59 str.writeBytes(o);
60 return o;
61}
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
66bool
67operator==(const StringView& a,const StringView& b)
68{
69 bool is_equal = (a.toStdStringView()==b.toStdStringView());
70 //std::cout << "COMPARE: a=" << a.length() << " '" << a << "'"
71 // << " b=" << b.length() << " '" << b << "' v=" << is_equal << '\n';
72 return is_equal;
73}
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
78bool operator==(const char* a,const StringView& b)
79{
80 return operator==(StringView(a),b);
81}
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
86bool operator==(const StringView& a,const char* b)
87{
88 return operator==(a,StringView(b));
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94bool operator<(const StringView& a,const StringView& b)
95{
96 return a.toStdStringView()<b.toStdStringView();
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102} // End namespace Arccore
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
Référence à une instance.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Definition Span.h:209
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
Definition Span.h:419
constexpr __host__ __device__ Span< T, DynExtent > subspan(Int64 abegin, Int64 asize) const
Sous-vue à partir de l'élément abegin et contenant asize éléments.
Definition Span.h:590
Vue sur une chaîne de caractères UTF-8.
Definition StringView.h:47
constexpr Int64 length() const ARCCORE_NOEXCEPT
Longueur en octet de la chaîne de caractères.
Definition StringView.h:99
StringView subView(Int64 pos) const
Sous-chaîne commençant à la position pos.
Definition StringView.cc:37
void writeBytes(std::ostream &o) const
Écrit la chaîne au format UTF-8 sur le flot o.
Definition StringView.cc:28
Espace de nom de Arccore.
Definition ArcaneTypes.h:29
bool operator<(const APReal &a, const APReal &b)
Emulation d'un réel en précision arbitraire.
std::int64_t Int64
Type entier signé sur 64 bits.