ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
strchar.cpp
Go to the documentation of this file.
1// Copyright (C) 1999-2005 Open Source Telecom Corporation.
2// Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
3// Copyright (C) 2015 Cherokees of Idaho.
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 of the License, or
8// (at your option) 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
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18//
19// As a special exception, you may use this file as part of a free software
20// library without restriction. Specifically, if other files instantiate
21// templates or use macros or inline functions from this file, or you compile
22// this file and link it with other files to produce an executable, this
23// file does not by itself cause the resulting executable to be covered by
24// the GNU General Public License. This exception does not however
25// invalidate any other reasons why the executable file might be covered by
26// the GNU General Public License.
27//
28// This exception applies only to the code released under the name GNU
29// Common C++. If you copy code from other releases into a copy of GNU
30// Common C++, as the General Public License permits, the exception does
31// not apply to the code that you add in this way. To avoid misleading
32// anyone as to the status of such modified files, you must delete
33// this exception notice from them.
34//
35// If you write modifications of your own for GNU Common C++, it is your choice
36// whether to permit this exception to apply to your modifications.
37// If you do not wish that, delete this exception notice.
38//
39
40#include <ucommon-config.h>
41#include <ctype.h>
42#include <commoncpp/config.h>
43#include <commoncpp/export.h>
44#include <commoncpp/string.h>
45#include <commoncpp/numbers.h>
46
47namespace ost {
48
49char *newString(const char *src, size_t size)
50{
51 char *dest;
52
53 if(!size)
54 size = strlen(src) + 1;
55
56 dest = new char[size];
57 return setString(dest, size, src);
58}
59
60void delString(char *str)
61{
62 delete[] str;
63}
64
65char *setUpper(char *string, size_t size)
66{
67 char *ret = string;
68
69 if(!size)
70 size = strlen(string);
71
72 while(size && *string) {
73 *string = toupper(*string);
74 ++string;
75 --size;
76 }
77
78 return ret;
79}
80
81char *setLower(char *string, size_t size)
82{
83 char *ret = string;
84
85 if(!size)
86 size = strlen(string);
87
88 while(size && *string) {
89 *string = tolower(*string);
90 ++string;
91 --size;
92 }
93
94 return ret;
95}
96
97char *rsetField(char *dest, size_t size, const char *src, const char fill)
98{
99 size_t len = 0;
100
101 if(src)
102 len = strlen(src);
103
104 if(len > size)
105 len = size;
106
107 if(len)
108 memmove(dest + size - len, (void *)src, len);
109
110 if(len < size && fill)
111 memset(dest, fill, size - len);
112
113 return dest;
114}
115
116char *lsetField(char *dest, size_t size, const char *src, const char fill)
117{
118 size_t len = 0;
119
120 if(src)
121 len = strlen(src);
122
123 if(len > size)
124 len = size;
125
126 if(len)
127 memmove(dest, src, len);
128
129 if(len < size && fill)
130 memset(dest + len, fill, size - len);
131
132 return dest;
133}
134
135} // namespace ost
Export interfaces for library interfaces.
Common C++ generic string class.
Definition: address.cpp:63
char * setLower(char *string, size_t size)
Definition: strchar.cpp:81
char * newString(const char *src, size_t size)
Definition: strchar.cpp:49
char * setUpper(char *string, size_t size)
Definition: strchar.cpp:65
char * rsetField(char *dest, size_t size, const char *src, const char fill)
Definition: strchar.cpp:97
void delString(char *str)
Definition: strchar.cpp:60
char * setString(char *target, size_t size, const char *str)
Definition: string.h:63
char * lsetField(char *dest, size_t size, const char *src, const char fill)
Definition: strchar.cpp:116
String str(Socket &so, size_t size)
Definition: socket.cpp:3507