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.
This commit is contained in:
Bruno Haible 2025-01-03 16:19:12 +01:00
parent fda80a7f5d
commit 85d8d8e106
10 changed files with 31 additions and 33 deletions

View File

@ -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

View File

@ -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 <ueno@gnu.org>, 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;

View File

@ -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 <haible@clisp.cons.org>, 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
{

View File

@ -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 <drepper@gnu.ai.mit.edu>, 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')

View File

@ -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 <millerp@canb.auug.org.au>
@ -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);

View File

@ -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 <bruno@clisp.org>, 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)

View File

@ -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 <bruno@clisp.org>, 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)

View File

@ -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;

View File

@ -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

View File

@ -18,6 +18,7 @@ gettimeofday
get_ppid_of
get_progname_of
stdint-h
str_startswith
terminfo-h
xalloc
xgethostname