Skip to content

Commit 58aab43

Browse files
committed
[arccore:base] Add substring() methods in StringView class
1 parent 3d70be2 commit 58aab43

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

arccore/src/base/arccore/base/StringView.cc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* StringView.cc (C) 2000-2021 */
8+
/* StringView.cc (C) 2000-2025 */
99
/* */
1010
/* Vue sur une chaîne de caractères UTF-8. */
1111
/*---------------------------------------------------------------------------*/
@@ -33,6 +33,26 @@ writeBytes(std::ostream& o) const
3333
/*---------------------------------------------------------------------------*/
3434
/*---------------------------------------------------------------------------*/
3535

36+
StringView StringView::
37+
substring(Int64 pos) const
38+
{
39+
return substring(pos, length() - pos);
40+
}
41+
42+
/*---------------------------------------------------------------------------*/
43+
/*---------------------------------------------------------------------------*/
44+
45+
StringView StringView::
46+
substring(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+
3656
std::ostream&
3757
operator<<(std::ostream& o,const StringView& str)
3858
{

arccore/src/base/arccore/base/StringView.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* StringView.h (C) 2000-2023 */
8+
/* StringView.h (C) 2000-2025 */
99
/* */
1010
/* Vue sur une chaîne de caractères UTF-8. */
1111
/*---------------------------------------------------------------------------*/
@@ -183,6 +183,12 @@ class ARCCORE_BASE_EXPORT StringView
183183
//! Écrit la chaîne au format UTF-8 sur le flot \a o
184184
void writeBytes(std::ostream& o) const;
185185

186+
//! Sous-chaîne commençant à la position \a pos
187+
StringView substring(Int64 pos) const;
188+
189+
//! Sous-chaîne commençant à la position \a pos et de longueur \a len
190+
StringView substring(Int64 pos,Int64 len) const;
191+
186192
private:
187193

188194
Span<const Byte> m_v;

0 commit comments

Comments
 (0)