Coverage Report

Created: 2026-03-12 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gettext/gettext-tools/src/msgl-ascii.c
Line
Count
Source
1
/* Message list test for ASCII character set.
2
   Copyright (C) 2001-2026 Free Software Foundation, Inc.
3
4
   This program is free software: you can redistribute it and/or modify
5
   it under the terms of the GNU General Public License as published by
6
   the Free Software Foundation; either version 3 of the License, or
7
   (at your option) any later version.
8
9
   This program is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
   GNU General Public License for more details.
13
14
   You should have received a copy of the GNU General Public License
15
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16
17
/* Written by Bruno Haible.  */
18
19
20
#include <config.h>
21
22
/* Specification.  */
23
#include "msgl-ascii.h"
24
25
#include "c-ctype.h"
26
27
28
/* This file's structure parallels msgl-iconv.c.  */
29
30
31
bool
32
is_ascii_string (const char *string)
33
0
{
34
0
  for (; *string; string++)
35
0
    if (!c_isascii ((unsigned char) *string))
36
0
      return false;
37
0
  return true;
38
0
}
39
40
bool
41
is_ascii_string_desc (string_desc_t string)
42
0
{
43
0
  size_t len = sd_length (string);
44
0
  for (size_t i = 0; i < len; i++)
45
0
    if (!c_isascii ((unsigned char) sd_char_at (string, i)))
46
0
      return false;
47
0
  return true;
48
0
}
49
50
bool
51
is_ascii_string_list (const string_list_ty *slp)
52
0
{
53
0
  if (slp != NULL)
54
0
    for (size_t i = 0; i < slp->nitems; i++)
55
0
      if (!is_ascii_string (slp->item[i]))
56
0
        return false;
57
0
  return true;
58
0
}
59
60
bool
61
is_ascii_message (const message_ty *mp)
62
0
{
63
0
  {
64
0
    const char *p = mp->msgstr;
65
0
    const char *p_end = p + mp->msgstr_len;
66
67
0
    for (; p < p_end; p++)
68
0
      if (!c_isascii ((unsigned char) *p))
69
0
        return false;
70
0
  }
71
72
0
  if (!is_ascii_string_list (mp->comment))
73
0
    return false;
74
0
  if (!is_ascii_string_list (mp->comment_dot))
75
0
    return false;
76
77
  /* msgid and msgid_plural are normally ASCII, so why checking?
78
     Because in complete UTF-8 environments they can be UTF-8, not ASCII.  */
79
0
  if (!is_ascii_string (mp->msgid))
80
0
    return false;
81
0
  if (mp->msgid_plural != NULL && !is_ascii_string (mp->msgid_plural))
82
0
    return false;
83
84
  /* Likewise for msgctxt.  */
85
0
  if (mp->msgctxt != NULL && !is_ascii_string (mp->msgctxt))
86
0
    return false;
87
88
  /* Likewise for the prev_* fields.  */
89
0
  if (mp->prev_msgctxt != NULL && !is_ascii_string (mp->prev_msgctxt))
90
0
    return false;
91
0
  if (mp->prev_msgid != NULL && !is_ascii_string (mp->prev_msgid))
92
0
    return false;
93
0
  if (mp->prev_msgid_plural != NULL && !is_ascii_string (mp->prev_msgid_plural))
94
0
    return false;
95
96
0
  return true;
97
0
}
98
99
bool
100
is_ascii_message_list (const message_list_ty *mlp)
101
0
{
102
0
  for (size_t j = 0; j < mlp->nitems; j++)
103
0
    if (!is_ascii_message (mlp->item[j]))
104
0
      return false;
105
106
0
  return true;
107
0
}
108
109
bool
110
is_ascii_msgdomain_list (const msgdomain_list_ty *mdlp)
111
0
{
112
0
  for (size_t k = 0; k < mdlp->nitems; k++)
113
0
    if (!is_ascii_message_list (mdlp->item[k]->messages))
114
0
      return false;
115
116
0
  return true;
117
0
}