From: Bruno Haible Date: Fri, 3 Jan 2025 15:19:12 +0000 (+0100) Subject: Refactor: Use function str_startswith. X-Git-Tag: v0.24~65 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=85d8d8e106c99bbb2c16fe6fbffdad5564dcb9bc;p=thirdparty%2Fgettext.git Refactor: Use function str_startswith. * libtextstyle/gnulib-local/lib/term-ostream.oo.c (should_enable_hyperlinks): Use str_startswith. * libtextstyle/gnulib-local/modules/term-ostream (Depends-on): Add str_startswith. * gettext-tools/src/cldr-plural.y (yylex): Use str_startswith. * gettext-tools/src/format-java.c (message_format_parse, choice_format_parse): Likewise. * gettext-tools/src/msgl-check.c (plural_help, check_header_entry): Likewise. * gettext-tools/src/read-catalog-abstract.c (parse_comment_filepos): Likewise. * gettext-tools/src/read-csharp.c (msgdomain_read_csharp): Likewise. * gettext-tools/src/write-csharp.c (msgdomain_write_csharp): Likewise. * gettext-tools/src/x-perl.c (skip_pod): Likewise. * autogen.sh (GNULIB_MODULES_TOOLS_FOR_SRC, GNULIB_MODULES_LIBGETTEXTPO): Add str_startswith. --- diff --git a/autogen.sh b/autogen.sh index a0e2ce1c4..11bdca36f 100755 --- a/autogen.sh +++ b/autogen.sh @@ -6,7 +6,7 @@ # # This script requires autoconf-2.64..2.72 and automake-1.13..1.17 in the PATH. -# Copyright (C) 2003-2024 Free Software Foundation, Inc. +# Copyright (C) 2003-2025 Free Software Foundation, Inc. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -241,6 +241,7 @@ if ! $skip_gnulib; then stdlib-h stpcpy stpncpy + str_startswith strchrnul strcspn strerror @@ -390,6 +391,7 @@ if ! $skip_gnulib; then stdlib-h stpcpy stpncpy + str_startswith strchrnul strerror string-desc diff --git a/gettext-tools/src/cldr-plural.y b/gettext-tools/src/cldr-plural.y index 49c7bddb1..19c272b94 100644 --- a/gettext-tools/src/cldr-plural.y +++ b/gettext-tools/src/cldr-plural.y @@ -1,5 +1,5 @@ /* Unicode CLDR plural rule parser and converter. - Copyright (C) 2015-2024 Free Software Foundation, Inc. + Copyright (C) 2015-2025 Free Software Foundation, Inc. This file was written by Daiki Ueno , 2015. @@ -326,27 +326,27 @@ yylex (YYSTYPE *lval, struct cldr_plural_parse_args *arg) arg->cp = exp + length; return ELLIPSIS; } - else if (strncmp ("...", exp, 3) == 0) + else if (str_startswith (exp, "...")) { arg->cp = exp + 3; return ELLIPSIS; } - else if (strncmp ("..", exp, 2) == 0) + else if (str_startswith (exp, "..")) { arg->cp = exp + 2; return RANGE; } - else if (strncmp ("other", exp, 5) == 0) + else if (str_startswith (exp, "other")) { arg->cp = exp + 5; return OTHER; } - else if (strncmp ("@integer", exp, 8) == 0) + else if (str_startswith (exp, "@integer")) { arg->cp = exp + 8; return AT_INTEGER; } - else if (strncmp ("@decimal", exp, 8) == 0) + else if (str_startswith (exp, "@decimal")) { arg->cp = exp + 8; return AT_DECIMAL; diff --git a/gettext-tools/src/format-java.c b/gettext-tools/src/format-java.c index 7de2bceae..c957b06e5 100644 --- a/gettext-tools/src/format-java.c +++ b/gettext-tools/src/format-java.c @@ -1,5 +1,5 @@ /* Java MessageFormat format strings. - Copyright (C) 2001-2004, 2006-2007, 2009, 2019, 2023 Free Software Foundation, Inc. + Copyright (C) 2001-2025 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -219,8 +219,8 @@ message_format_parse (const char *format, char *fdi, struct spec *spec, type = FAT_OBJECT; if (*element == '\0') ; - else if (strncmp (element, ",time", 5) == 0 - || strncmp (element, ",date", 5) == 0) + else if (str_startswith (element, ",time") + || str_startswith (element, ",date")) { type = FAT_DATE; element += 5; @@ -255,7 +255,7 @@ message_format_parse (const char *format, char *fdi, struct spec *spec, return false; } } - else if (strncmp (element, ",number", 7) == 0) + else if (str_startswith (element, ",number")) { type = FAT_NUMBER; element += 7; @@ -289,7 +289,7 @@ message_format_parse (const char *format, char *fdi, struct spec *spec, return false; } } - else if (strncmp (element, ",choice", 7) == 0) + else if (str_startswith (element, ",choice")) { type = FAT_NUMBER; /* because ChoiceFormat extends NumberFormat */ element += 7; @@ -543,7 +543,7 @@ choice_format_parse (const char *format, struct spec *spec, number_nonempty = false; while (*format != '\0' && !(!quoting && (*format == '<' || *format == '#' - || strncmp (format, "\\u2264", 6) == 0 + || str_startswith (format, "\\u2264") || *format == '|'))) { if (format[0] == '\\') @@ -576,7 +576,7 @@ choice_format_parse (const char *format, struct spec *spec, if (*format == '<' || *format == '#') format += 1; - else if (strncmp (format, "\\u2264", 6) == 0) + else if (str_startswith (format, "\\u2264")) format += 6; else { diff --git a/gettext-tools/src/msgl-check.c b/gettext-tools/src/msgl-check.c index 3d944dcc8..46471cc56 100644 --- a/gettext-tools/src/msgl-check.c +++ b/gettext-tools/src/msgl-check.c @@ -1,5 +1,5 @@ /* Checking of messages in PO files. - Copyright (C) 1995-2023 Free Software Foundation, Inc. + Copyright (C) 1995-2025 Free Software Foundation, Inc. Written by Ulrich Drepper , April 1995. This program is free software: you can redistribute it and/or modify @@ -213,9 +213,7 @@ plural_help (const char *nullentry) language += 15; for (j = 0; j < plural_table_size; j++) - if (strncmp (language, - plural_table[j].language, - strlen (plural_table[j].language)) == 0) + if (str_startswith (language, plural_table[j].language)) { ptentry = &plural_table[j]; break; @@ -782,8 +780,7 @@ check_header_entry (const message_ty *mp, const char *msgstr_string, if (*p == ' ') p++; if (default_values[cnt] != NULL - && strncmp (p, default_values[cnt], - strlen (default_values[cnt])) == 0) + && str_startswith (p, default_values[cnt])) { p += strlen (default_values[cnt]); if (*p == '\0' || *p == '\n') diff --git a/gettext-tools/src/read-catalog-abstract.c b/gettext-tools/src/read-catalog-abstract.c index ea455c10e..e42b6b8f8 100644 --- a/gettext-tools/src/read-catalog-abstract.c +++ b/gettext-tools/src/read-catalog-abstract.c @@ -1,5 +1,5 @@ /* Reading textual message catalogs (such as PO files), abstract class. - Copyright (C) 1995-2024 Free Software Foundation, Inc. + Copyright (C) 1995-2025 Free Software Foundation, Inc. This file was written by Peter Miller @@ -261,8 +261,7 @@ parse_comment_filepos (abstract_catalog_reader_ty *catr, const char *s) { bool isolated_filename = (catr->po_lex_isolate_start != NULL - && strncmp (s, catr->po_lex_isolate_start, - strlen (catr->po_lex_isolate_start)) == 0); + && str_startswith (s, catr->po_lex_isolate_start)); if (isolated_filename) s += strlen (catr->po_lex_isolate_start); @@ -278,8 +277,7 @@ parse_comment_filepos (abstract_catalog_reader_ty *catr, const char *s) filename_end = s; break; } - if (strncmp (s, catr->po_lex_isolate_end, - strlen (catr->po_lex_isolate_end)) == 0) + if (str_startswith (s, catr->po_lex_isolate_end)) { filename_end = s; s += strlen (catr->po_lex_isolate_end); diff --git a/gettext-tools/src/read-csharp.c b/gettext-tools/src/read-csharp.c index bc02dd64b..de6602346 100644 --- a/gettext-tools/src/read-csharp.c +++ b/gettext-tools/src/read-csharp.c @@ -1,5 +1,5 @@ /* Reading C# satellite assemblies. - Copyright (C) 2003-2024 Free Software Foundation, Inc. + Copyright (C) 2003-2025 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify @@ -117,7 +117,7 @@ msgdomain_read_csharp (const char *resource_name, const char *locale_name, for (p = culture_name; *p != '\0'; p++) if (*p == '_') *p = '-'; - if (strncmp (culture_name, "sr-CS", 5) == 0) + if (str_startswith (culture_name, "sr-CS")) memcpy (culture_name, "sr-SP", 5); p = strchr (culture_name, '@'); if (p != NULL) diff --git a/gettext-tools/src/write-csharp.c b/gettext-tools/src/write-csharp.c index dac983d8f..c0250eadf 100644 --- a/gettext-tools/src/write-csharp.c +++ b/gettext-tools/src/write-csharp.c @@ -1,5 +1,5 @@ /* Writing C# satellite assemblies. - Copyright (C) 2003-2024 Free Software Foundation, Inc. + Copyright (C) 2003-2025 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify @@ -674,7 +674,7 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding, for (p = culture_name; *p != '\0'; p++) if (*p == '_') *p = '-'; - if (strncmp (culture_name, "sr-CS", 5) == 0) + if (str_startswith (culture_name, "sr-CS")) memcpy (culture_name, "sr-SP", 5); p = strchr (culture_name, '@'); if (p != NULL) diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index 60c25efd6..77826490a 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -536,7 +536,7 @@ skip_pod (struct perl_extractor *xp) ++(xp->line_number); - if (strncmp ("=cut", xp->linebuf, 4) == 0) + if (str_startswith (xp->linebuf, "=cut")) { /* Force reading of a new line on next call to phase1_getc(). */ xp->linepos = xp->linesize; diff --git a/libtextstyle/gnulib-local/lib/term-ostream.oo.c b/libtextstyle/gnulib-local/lib/term-ostream.oo.c index 932231459..a7b08bb70 100644 --- a/libtextstyle/gnulib-local/lib/term-ostream.oo.c +++ b/libtextstyle/gnulib-local/lib/term-ostream.oo.c @@ -2351,7 +2351,7 @@ should_enable_hyperlinks (const char *term) --------------------+-------------+--------------------- emacs-terminal 26.1 | eterm-color | produces garbage */ - if (strncmp (term, "eterm", 5) == 0) + if (str_startswith (term, "eterm")) return false; /* xterm-compatible terminal emulators: @@ -2368,13 +2368,13 @@ should_enable_hyperlinks (const char *term) TODO: Revisit this table periodically. */ - if (strncmp (term, "xterm", 5) == 0) + if (str_startswith (term, "xterm")) { char *progname = get_terminal_emulator_progname (); if (progname != NULL) { bool known_buggy = - strncmp (progname, "python", 6) == 0 /* guake */ + str_startswith (progname, "python") /* guake */ || strcmp (progname, "lilyterm") == 0 || strcmp (progname, "lterm") == 0 || strcmp (progname, "lxterminal") == 0 diff --git a/libtextstyle/gnulib-local/modules/term-ostream b/libtextstyle/gnulib-local/modules/term-ostream index c68f28136..f63d01979 100644 --- a/libtextstyle/gnulib-local/modules/term-ostream +++ b/libtextstyle/gnulib-local/modules/term-ostream @@ -18,6 +18,7 @@ gettimeofday get_ppid_of get_progname_of stdint-h +str_startswith terminfo-h xalloc xgethostname