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