14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci/*
174514f5e3Sopenharmony_ci * @tc.name:stringreplaceall
184514f5e3Sopenharmony_ci * @tc.desc:test stringreplaceall
194514f5e3Sopenharmony_ci * @tc.type: FUNC
204514f5e3Sopenharmony_ci * @tc.require: issueIATECS
214514f5e3Sopenharmony_ci */
224514f5e3Sopenharmony_ci
234514f5e3Sopenharmony_ci// case1 - string: utf8, search: not regexp, replace: no dollar
244514f5e3Sopenharmony_cilet str1 = "Hello, world";
254514f5e3Sopenharmony_cilet res1 = str1.replaceAll("o", "o-o");
264514f5e3Sopenharmony_ciprint(res1);
274514f5e3Sopenharmony_ci
284514f5e3Sopenharmony_ci// case2 - string: utf8, search: regexp, replace: no dollar
294514f5e3Sopenharmony_cilet res2 = str1.replaceAll(/o/g, "o-o");
304514f5e3Sopenharmony_ciprint(res2);
314514f5e3Sopenharmony_ci
324514f5e3Sopenharmony_ci// case3 - string: utf8, search: regexp, replace: dollar
334514f5e3Sopenharmony_cilet res3 = str1.replaceAll(/o/g, "$&-$&");
344514f5e3Sopenharmony_ciprint(res3);
354514f5e3Sopenharmony_ci
364514f5e3Sopenharmony_ci// case4 - string: utf8, search: not regexp, replace: dollar
374514f5e3Sopenharmony_cilet res4 = str1.replaceAll("o", "$&-$&");
384514f5e3Sopenharmony_ciprint(res4);
394514f5e3Sopenharmony_ci
404514f5e3Sopenharmony_ci// case5 - string: utf8, search: not regexp, replace: function
414514f5e3Sopenharmony_cilet res5 = str1.replaceAll("o", String);
424514f5e3Sopenharmony_ciprint(res5);
434514f5e3Sopenharmony_ci
444514f5e3Sopenharmony_ci// case6 - string: utf16, search: not regexp, replace: no dollar
454514f5e3Sopenharmony_cilet str3 = "你好,世界!你好,世界!";
464514f5e3Sopenharmony_cilet res6 = str3.replaceAll("好", "好-好");
474514f5e3Sopenharmony_ciprint(res6);
484514f5e3Sopenharmony_ci
494514f5e3Sopenharmony_ci// case7 - string: utf16, search: regexp, replace: no dollar
504514f5e3Sopenharmony_cilet res7 = str3.replaceAll(/好/g, "好-好");
514514f5e3Sopenharmony_ciprint(res7);
524514f5e3Sopenharmony_ci
534514f5e3Sopenharmony_ci// case8 - string: utf16, search: regexp, replace: dollar
544514f5e3Sopenharmony_cilet res8 = str3.replaceAll(/好/g, "$&-$&");
554514f5e3Sopenharmony_ciprint(res8);
564514f5e3Sopenharmony_ci
574514f5e3Sopenharmony_ci// case9 - string: utf16, search: not regexp, replace: dollar
584514f5e3Sopenharmony_cilet res9 = str3.replaceAll("好", "$&-$&");
594514f5e3Sopenharmony_ciprint(res9);
604514f5e3Sopenharmony_ci
614514f5e3Sopenharmony_ci// case10 - string: utf16, search: not regexp, replace: function
624514f5e3Sopenharmony_cilet res10 = str3.replaceAll("好", String);
634514f5e3Sopenharmony_ciprint(res10);
64