Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TestStringView.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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#include <gtest/gtest.h>
8
9#include "arccore/base/StringView.h"
10#include "arccore/base/String.h"
11
12#include <iostream>
13
14using namespace Arccore;
15
16TEST(StringView, StdStringView)
17{
18 const char* ref1 = "S1éà";
19 const char* ref2 = "ù*aXZáé";
20 // Ref3 = Ref1 + Ref2
21 const char* ref3 = "S1éàù*aXZáé";
22 std::string std_ref3 { ref3 };
23 String snull;
24 String sempty { "" };
25 StringView s1 = ref1;
26 StringView s2 = ref2;
27 String s3 = ref1;
28 s3 = s3 + ref2;
29 std::cout << "S2 '" << s2 << "'_SIZE=" << s2.length() << '\n';
30 std::cout << "S3 '" << s3 << "'_SIZE=" << s3.length() << '\n';
31 std::string_view vempty = sempty.toStdStringView();
32 ASSERT_EQ((Int64)vempty.size(),0) << "vempty.size()==0";
33 std::string_view vnull = snull.toStdStringView();
34 ASSERT_EQ((Int64)vnull.size(),0) << "vnull.size()==0";
35 std::string_view v1 = s1.toStdStringView();
36 std::cout << "S1 '" << s1 << "'_SIZE=" << s1.length() << " V1 " << v1.size() << " ='" << v1 << "'" << '\n';
37 ASSERT_EQ(v1,ref1) << "v1==ref1";
38 std::string_view v2 = s2.toStdStringView();
39 std::cout << "S2 '" << s2 << "'_SIZE=" << s2.length() << " V2 " << v2.size() << " ='" << v2 << "'" << '\n';
40 ASSERT_EQ(v2,ref2) << "v2==ref2";
41 std::string_view v3 = s3.toStdStringView();
42 std::cout << "S3 '" << s3 << "'_SIZE=" << s3.length() << " V3 " << v3.size() << " ='" << v3 << "'" << '\n';
43 ASSERT_EQ(v3,std_ref3) << "v3==ref3";
44
45 String s4 = s3 + snull;
46 std::cout << "S4 '" << s4 << "'_SIZE=" << s4.length() << '\n';
47 ASSERT_EQ(s4.length(),s3.length());
48 StringView v4 = s4.view();
49 std::cout << "S4 '" << s4 << "'_SIZE=" << s4.length() << " V4 " << v4.size() << " ='" << v4 << "'" << '\n';
50 ASSERT_EQ(v4,v3) << "v4==v3";
51
52 String s5 = s3 + sempty;
53 std::cout << "S5 '" << s5 << "'_SIZE=" << s5.length() << '\n';
54 StringView v5 = s5.view();
55 std::cout << "S5 '" << s5 << "'_SIZE=" << s5.length() << " V5 " << v5.size() << " ='" << v5 << "'" << '\n';
56 ASSERT_EQ(v5,v4) << "v5==v4";
57}
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
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
std::string_view toStdStringView() const ARCCORE_NOEXCEPT
Retourne une vue de la STL de la vue actuelle.
Definition StringView.h:112
constexpr Int64 size() const ARCCORE_NOEXCEPT
Longueur en octet de la chaîne de caractères.
Definition StringView.h:102
Chaîne de caractères unicode.
StringView view() const
Retourne une vue sur la chaîne actuelle.
Definition String.cc:367
Int64 length() const
Retourne la longueur de la chaîne.
Definition String.cc:338
std::string_view toStdStringView() const
Retourne une vue de la STL sur la chaîne actuelle.
Definition String.cc:348
Espace de nom de Arccore.
Definition ArcaneTypes.h:24