source: mainline/uspace/lib/posix/ctype.c@ 6921178

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6921178 was 6921178, checked in by Petr Koupy <petr.koupy@…>, 14 years ago

Edited or removed some TODO/FIXME comments.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Zarevucky
3 * Copyright (c) 2011 Petr Koupy
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libposix
31 * @{
32 */
33/** @file Character classification.
34 */
35
36#define LIBPOSIX_INTERNAL
37
38#include "ctype.h"
39
40/**
41 * Checks whether character is a hexadecimal digit.
42 *
43 * @param c Character to inspect.
44 * @return Non-zero if character match the definition, zero otherwise.
45 */
46int posix_isxdigit(int c)
47{
48 return isdigit(c) ||
49 (c >= 'a' && c <= 'f') ||
50 (c >= 'A' && c <= 'F');
51}
52
53/**
54 * Checks whether character is a word separator.
55 *
56 * @param c Character to inspect.
57 * @return Non-zero if character match the definition, zero otherwise.
58 */
59int posix_isblank(int c)
60{
61 return c == ' ' || c == '\t';
62}
63
64/**
65 * Checks whether character is a control character.
66 *
67 * @param c Character to inspect.
68 * @return Non-zero if character match the definition, zero otherwise.
69 */
70int posix_iscntrl(int c)
71{
72 return c < 0x20 || c == 0x7E;
73}
74
75/**
76 * Checks whether character is any printing character except space.
77 *
78 * @param c Character to inspect.
79 * @return Non-zero if character match the definition, zero otherwise.
80 */
81int posix_isgraph(int c)
82{
83 return posix_isprint(c) && c != ' ';
84}
85
86/**
87 * Checks whether character is a printing character.
88 *
89 * @param c Character to inspect.
90 * @return Non-zero if character match the definition, zero otherwise.
91 */
92int posix_isprint(int c)
93{
94 return posix_isascii(c) && !posix_iscntrl(c);
95}
96
97/**
98 * Checks whether character is a punctuation.
99 *
100 * @param c Character to inspect.
101 * @return Non-zero if character match the definition, zero otherwise.
102 */
103int posix_ispunct(int c)
104{
105 return !isspace(c) && !isalnum(c) && posix_isprint(c);
106}
107
108/**
109 * Checks whether character is ASCII. (obsolete)
110 *
111 * @param c Character to inspect.
112 * @return Non-zero if character match the definition, zero otherwise.
113 */
114extern int posix_isascii(int c)
115{
116 return c >= 0 && c < 128;
117}
118
119/**
120 * Converts argument to a 7-bit ASCII character. (obsolete)
121 *
122 * @param c Character to convert.
123 * @return Coverted character.
124 */
125extern int posix_toascii(int c)
126{
127 return c & 0x7F;
128}
129
130/** @}
131 */
Note: See TracBrowser for help on using the repository browser.