source: branches/samba-3.0/source/iniparser/src/strlib.c@ 298

Last change on this file since 298 was 1, checked in by Paul Smedley, 19 years ago

Initial code import

File size: 5.6 KB
Line 
1
2/*-------------------------------------------------------------------------*/
3/**
4 @file strlib.c
5 @author N. Devillard
6 @date Jan 2001
7 @version $Revision: 1.8 $
8 @brief Various string handling routines to complement the C lib.
9
10 This modules adds a few complementary string routines usually missing
11 in the standard C library.
12*/
13/*--------------------------------------------------------------------------*/
14
15/*
16 $Id: strlib.c,v 1.8 2002/12/12 10:29:16 ndevilla Exp $
17 $Author: ndevilla $
18 $Date: 2002/12/12 10:29:16 $
19 $Revision: 1.8 $
20*/
21
22/*---------------------------------------------------------------------------
23 Includes
24 ---------------------------------------------------------------------------*/
25
26#include <string.h>
27#include <ctype.h>
28
29#include "strlib.h"
30
31/*---------------------------------------------------------------------------
32 Defines
33 ---------------------------------------------------------------------------*/
34#define ASCIILINESZ 1024
35
36/*---------------------------------------------------------------------------
37 Function codes
38 ---------------------------------------------------------------------------*/
39
40
41/*-------------------------------------------------------------------------*/
42/**
43 @brief Convert a string to lowercase.
44 @param s String to convert.
45 @return ptr to statically allocated string.
46
47 This function returns a pointer to a statically allocated string
48 containing a lowercased version of the input string. Do not free
49 or modify the returned string! Since the returned string is statically
50 allocated, it will be modified at each function call (not re-entrant).
51 */
52/*--------------------------------------------------------------------------*/
53
54char * strlwc(const char * s)
55{
56 static char l[ASCIILINESZ+1];
57 int i ;
58
59 if (s==NULL) return NULL ;
60 memset(l, 0, ASCIILINESZ+1);
61 i=0 ;
62 while (s[i] && i<ASCIILINESZ) {
63 l[i] = (char)tolower((int)s[i]);
64 i++ ;
65 }
66 l[ASCIILINESZ]=(char)0;
67 return l ;
68}
69
70
71
72/*-------------------------------------------------------------------------*/
73/**
74 @brief Convert a string to uppercase.
75 @param s String to convert.
76 @return ptr to statically allocated string.
77
78 This function returns a pointer to a statically allocated string
79 containing an uppercased version of the input string. Do not free
80 or modify the returned string! Since the returned string is statically
81 allocated, it will be modified at each function call (not re-entrant).
82 */
83/*--------------------------------------------------------------------------*/
84
85char * strupc(char * s)
86{
87 static char l[ASCIILINESZ+1];
88 int i ;
89
90 if (s==NULL) return NULL ;
91 memset(l, 0, ASCIILINESZ+1);
92 i=0 ;
93 while (s[i] && i<ASCIILINESZ) {
94 l[i] = (char)toupper((int)s[i]);
95 i++ ;
96 }
97 l[ASCIILINESZ]=(char)0;
98 return l ;
99}
100
101
102
103/*-------------------------------------------------------------------------*/
104/**
105 @brief Skip blanks until the first non-blank character.
106 @param s String to parse.
107 @return Pointer to char inside given string.
108
109 This function returns a pointer to the first non-blank character in the
110 given string.
111 */
112/*--------------------------------------------------------------------------*/
113
114char * strskp(char * s)
115{
116 char * skip = s;
117 if (s==NULL) return NULL ;
118 while (isspace((int)*skip) && *skip) skip++;
119 return skip ;
120}
121
122
123
124/*-------------------------------------------------------------------------*/
125/**
126 @brief Remove blanks at the end of a string.
127 @param s String to parse.
128 @return ptr to statically allocated string.