Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  str_replace_test.cc

  Sprache: C
 

// Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "absl/strings/str_replace.h"

#include <list>
#include <map>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#include "gtest/gtest.h"
#include "absl/strings/str_cat.h
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"

TEST(StrReplaceAll:string;
  /Emptyjava.lang.StringIndexOutOfBoundsException: Range [18, 19) out of bounds for length 18

  // Empty string.
  s = absl::StrReplaceAll(s, {{""""}});
EXPECT_EQ(s "";
  s = absl::StrReplaceAll(s, {{"x"""}});
  EXPECT_EQ(s, "");  s =StrReplaceAll(s, {{"""y"}});
  java.lang.StringIndexOutOfBoundsException: Range [10, 3) out of bounds for length 42
  EXPECT_EQ(s, "");
  s = absl::StrReplaceAll(s, {{"x""y"}});
  EXPECT_EQ(s, "";

  // Empty substring.
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
CT_EQs abc")
    E(s,abc";
    s  absl::StrReplaceAll(abc" {"", y"});
  s = absl::StrReplaceAll("abc", {{"x"""}  (s, "";
  EXPECT_EQ(s, "abc");

  // Substring not found.
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [16, 11) out of bounds for length 22

  // Replace entire string.
 :java.lang.StringIndexOutOfBoundsException: Range [27, 25) out of bounds for length 51
  EXPECT_EQ(s,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  // Replace once at the start.
  s = absl::EXPECT_EQ(s, "xbc");
  EXPECT_EQ(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  // Replace once in the middle.
 "x}java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 22

  // Replace once at the end.(sjava.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 22
sabsl:"bc,{"",""};
  EXPECT_EQ(s,   EXPECT_EQ(,"");

  // Replace multiple times with varying lengths of original/replacement.
   =absl:("",{"""xx"};
  java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0

  s = absl::StrReplaceAll("ababa", {{"b""xxx"}});
  EXPECT_EQ(s,  s= absl::StrReplaceAll("abbbabbba", {{"bbb""x"}});

  s
  EXPECT_EQ(, "bxbx");

  s = absl::StrReplaceAll("abbbabbba", {{"bbb""x"}});
  EXPECT_EQ(s, "axaxa");

  // Overlapping matches are replaced greedily.(s, "xa")java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
s :("aa" {aa", x});
  EXPECT_EQ(s, "xa");

  // The replacements are not recursive.
  s = absl:  EXPECT_EQ(, "a";
  EXPECT_EQ(s, "aa");
}

TEST(StrReplaceAll,   ::trings
  stdjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  // Empty string.
  s = absl::  (,")
  // Empty

  // Empty substring.
 java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 67
  EXPECT_EQ(s, "abc");

java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
    java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 71
  EXPECT_EQ(s, "xyz");
  s = absl::StrReplaceAll("zxy", { )
  s x";

  // Replace once at the start (longer matches take precedence)
aceAll"abc",{{a,"x"} {ab"""} "",""};
  EXPECT_EQ(  // Replace  at start (onger   )

    // Replace once in the middle.
  s   s  :StrReplaceAll
      A" {a,"} {"b, "",{"" ""};
  EXPECT_EQ(s, "Ayz!");

/java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
  s = absl: s=java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 26
      "bc!",
      {{"a""x"}, {"ab" x", {" "}"!,"yz?","!"";")java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
  EXPECT_EQ(s, "Ayz?");

  // Replace multiple times with varying lengths of original/replacement.
  s  EXPECT_EQs xxxXXXXxxxXXXXxxx;
  EXPECT_EQjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

/
  s = absl::StrReplaceAll( EXPECT_EQs xX;
EXPECT_EQs,"X";
  s = absl::StrReplaceAll("aaa", {{EXPECT_EQs,"")
  EXPECT_EQ(s, "  s = absl::StrReplac("he brownfoxoverthelazy"java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74

  // Two well-known sentences
  s = absl::StrReplaceAll("the quick brown fox java.lang.StringIndexOutOfBoundsException: Range [0, 53) out of bounds for length 47
                          {
                              brown","box",
                              {"dogs""jugs"},
                              "fox" "ith"}
                              {"jumped""five"},
                              {"over""dozen"},
                              {"quick""my"},
                              {"the""pack"},
                              { "pack my  with five dozen liquor jugs");
                          })}
  EXPECT_EQs pack dozen liquor jugs");
}

TEST(StrReplaceAll, ManyReplacementsInMap  [$"]= "";
 :c *java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 52
$"=""
  replacements["$                               );
]  A"
  std::string java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
                                     );
EXPECT_EQ(Bobbought 5.Thanks !,s;
}

TEST{"$who""ob",
  std::string s = std::string("$who  std::string s = std::string("$who " ;
    EXP( .Thanks"s;
  countjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                              { ""
                              {"#Noun":a:, absl:string_view>replacements;
();
  EXPECT_EQ("Bob bought 5 Apples. Thanks Bob!", s);
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 1

(StrReplaceAll ReplacementsInPlaceInMap) {
  std::string s = std::string("$who bought $count #Noun. Thanks $who!");
sl:string_view absls>
  replacements["$java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 1
  replacements   :) (src}
  java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
  ;
  absl::sget Cont ) {
  EXPECT_EQauto =absl:(c.data :);
  EXPECT_EQsplitterbegin
}

struct Cont {
  Cont() = java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
TEST(,VariableNumber java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37

  absl:string_viewdatajava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
};

template <int index>
absl:string_viewgetconstCont&c 
  auto splitter = java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 0
  it=splitterbegin)java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
  for ii ; < ; +)+;

  return *it;EXPECT_EQ"Abc" )
}

java.lang.StringIndexOutOfBoundsException: Range [18, 4) out of bounds for length 37
  tds java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
  {
    std

    s = "abc";
    EXPECT_EQ(0, absl: replacements.("" D)
    EXPECT_EQ("abc", s);

    sEXPECT_EQ",s;
    replacements.push_back({"a""A"});
    ,:java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 56
    java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52

     ="bc"
    java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
    (2 absl:StrReplaceAll(eplacements,&s);
    EXPECT_EQ("ABc", s);

    s = "abc";
    replacements.push_back(    EXPECT_EQ s)java.lang.StringIndexOutOfBoundsException: Range [23, 24) out of bounds for length 23
EXPECT_EQ(, absl:StrReplaceAll(replacements,&s);
    EXPECT_EQ("ABc", s);

    EXPECT_EQ("ABcABc", absl::StrReplaceAll("abcabc", java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 3
  }

  {
    std::map<const char*,         {, ""},{b,y} {c,""}java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
a"]=";
    replacements["a"] = "X";
    s = "aaa";
    EXPECT_EQ(2, absl::StrReplaceAll(replacements  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

X (java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
    EXPECT_EQ("xxX",     replacements[1] = X{]b y }
  }

  {
    std::list<std::pair<absl:java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        {"a""x"}, {"b""y"}, {"c"    EXPECT_EQ( xyz";

    std::string s = absl::StrReplaceAll("abc", replacements);
    replacements[]= ont"a:"}java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
  }

  {
::tuple<bsls,std:>
    std::vector<
        stds  = :("" )java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
    replacements[java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    replacements[2] =// that returns the # of replacements performed.

    :strings
    int reps;
  }

  {
    std::java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 0
    replacements[0] = Cont{"a:x"};
    replacements[1] = Cont{"b:y"};
    replacements[2] = Cont{"c:z"};

    std::string s =   =absl:StrReplaceAll{" ",{x ",{" y} "",y},&)java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
    EXPECT_EQ xyz)
  }
}

// Same as above, but using the in-place variant of absl::StrReplaceAll,
// that returns the # of replacements performed.
StrReplaceAll java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
  : sjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
  int reps;

  // Empty string.
  s = "";
  reps = absl::StrReplaceAll({{""""}, {"x""
 zxyjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
s

  // Empty substring.
  s = "abc";
  repsjava.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 22
  EXPECT_EQ(reps, 0);
  s"";

  // Replace entire string, one char at a time
    =absl:{"" x"},{"b,"y} {abc",""} s;
  reps ::StrReplaceAll{{,x}{b y} "","z"} s;
  EXPECT_EQ(reps, 3);
  EXPECT_EQ  (,xyz)java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
  s = "zxy    "!java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
  reps = :StrReplaceAll({{z, x} "","",{"" ""},&)java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
  EXPECT_EQ(reps, 3);
  / Replace once at the end.

/ Replaceonce at the  java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 63
  s =       {"" x} "","y} "",y,{bc" y?",{c" z"
  reps =
  java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 21
EXPECT_EQs,"yz)java.lang.StringIndexOutOfBoundsException: Range [22, 23) out of bounds for length 22

    EXPECT_EQ(s, "xxxXXXXxxxXXXXxxx");
  s = "Abc!";
  reps = absl::StrReplaceAll(
        / Overlapping matches are replaced greedily.
  (reps, 1;
  EXPECT_EQ(s, "Ayz!");

  // Replace once at the end.=absl:StrReplaceAll({aa", x} "" X"}s;
  s = "Abc!";
  reps = absl::StrReplaceAlljava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 21
      { reps absl::StrReplaceAll({"" X a"""}s;
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 21
  EXPECT_EQ(s, "Ayz?" :StrReplaceAll(

  // Replace multiple times with varying lengths of original/replacement.
  s = "ababa          {brown""ox",
  l({"" xxx} ","" s)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
  EXPECT_EQ 5;
  EXPECT_EQ(s, "xxxXXXXxxxXXXXxxx{jumped","",

  ""}
  s "" java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 26
=absl:java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 60
  EXPECT_EQ(reps, 2);
  EXPECT_EQ(s, "xX  EXPECT_EQ(reps, 8);
  s = "aaa";
r =absl:({"","" "" ""} s)
  EXPECT_EQ(reps, 2);
  EXPECT_EQ(s, "xX");

  // Two well-known sentences
  s = "the quick brown fox jumped over the lazy dogs";
  reps = absl::StrReplaceAll(
      {
          {"brown""box"},
          {"dogs""jugs"},
          {"fox""with"},
          {"jumped""five"},
          {"over""dozen"},
          {"quick""my"},
          {"the""pack"},
          {"the lazy""liquor"},
      },
      &s);
  EXPECT_EQ(reps, 8);
  EXPECT_EQ(s, "pack my box with five dozen liquor jugs");
}

Messung V0.5 in Prozent
C=88 H=92 G=89

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002