The Main library header. More...
#include "bool.h"
Go to the source code of this file.
Typedefs | |
typedef char * | string |
Just an alias: string is easier to use and rember than char* . | |
typedef unsigned int | uint |
Just an alias: uint is easier to use and rember than unsigned int. | |
Functions | |
string | sp_new_string (const string str) |
Creates a new string as a copy of str. | |
string | sp_new_empty_string (int len) |
Creates a new empty string that can store at most len chars. | |
string | sp_strcpy (string copy, const string original, int offset) |
Copies the string pointed by original into copy starting from the offset specified. | |
void | sp_free (string str) |
Free a string previously dinamically created. | |
int | sp_strlen (const string str) |
An strlen clone, it calculates the length of the string str, not including the terminating '\0' character. | |
bool | sp_strcmp (const string str1, const string str2) |
Similar to strcmp, it compares two strings. | |
string | sp_strcat (const string str1, const string str2) |
Similar to strcat, but differently from that one, it creates a NEW string. | |
string | sp_lower_case (const string str) |
Create a NEW string, with the same content as str but lowercase. | |
string | sp_upper_case (const string str) |
Create a NEW string, with the same content as str but uppercase. |
The Main library header.
Copyright (C) 2010
Andrea Florio 2010 <andrea@opensuse.org>
Giuseppe Grassi 2010 <gra.giu@alice.it>
This Project is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This Project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
char * string |
Just an alias: string is easier to use and rember than char* .
unsigned int uint |
Just an alias: uint is easier to use and rember than unsigned int.
void sp_free | ( | string | str | ) |
Create a NEW string, with the same content as str but lowercase.
str | Is the string to convert to lowercase. |
string sp_new_empty_string | ( | int | len | ) |
Similar to strcat, but differently from that one, it creates a NEW string.
Example:
str1 = "hello"; str2 = "world"; string test = sp_strcat(const string str1, const string str2);
test will be: helloworld .
Copies the string pointed by original into copy starting from the offset specified.
The terminating null byte ('\0') is automatically added. The strings may not overlap, and
the destination string copy must be large enough to contain original + offset.
copy | Is the destination string. | |
original | Is the string that will be copied into copy. | |
offset | Is a POSITIVE offset from where original will be copied. |
// The string copy can store at most 20 chars string copy = sp_new_empty_strig(20); // but the 'copy' lenght IS now only 4 copy = sp_new_string("test"); sp_strcpy(copy, "hello", 3);
Now the string copy will be "teshello".
This case looks ok, infact the array copy can store 20 chars; sp_strlen ("hello")+offset == 7, and 7 < 20.
But here:
// Create a string copy // As before, the 'copy' lenght IS 4 string copy = "test"; sp_strcpy(copy, "hello", 3);
Here we'll have a buffer-overflow.
Because the array copy can store only 4 chars, and sp_strlen ("hello")+offset == 7, 7 > 4.
The new string simply doesn't fit.
int sp_strlen | ( | const string | str | ) |
An strlen clone, it calculates the length of the string str, not including the terminating '\0' character.
str | Is the string witch we need to know the lenght. |
Create a NEW string, with the same content as str but uppercase.
str | Is the string to convert to uppercase. |