Main Page   File List   File Members  

gstr_utils.h File Reference

A collection of utilities for working with GStrings. More...

#include <glib.h>

Go to the source code of this file.

Defines

#define __P(protos)    protos

Functions

GString* g_string_strip (GString *str)
 Strip the string of any trailing white spaces. More...

void g_string_delete_char (GString *str, gint pos)
 Delete a character from the string. More...

void g_string_insert_char (GString *str, gchar chr, gint pos)
 Insert a character into a string. More...

void g_string_insert_str (GString *str1, gchar *str2, gint pos)
 Insert a string into a string. More...

void g_string_escape_char (GString *str, gchar chr)
 Backslash escape occurrances of characters within a string. More...

void g_string_prepare_db_instr (GString *str)
 Prepare a SQL string for sending to the database. More...

void g_string_prepare_html (GString *str)
 Prepare a string for use within an HTML document. More...


Detailed Description

A collection of utilities for working with GStrings.

The functions contained here perform useful operations on GStrings. Some of these functions are just nice things to be able to do, other functions are specific to working with PostgreSQL databases.

Author(s):
Kenneth W. Sodemann (stufflehead@bigfoot.com)
Revision:
1.4
Date:
2000/12/25 14:55:42


Function Documentation

void g_string_delete_char ( GString * str,
gint pos )
 

Delete a character from the string.

Delete the character at the position given. Shift all following characters to the left.

Parameters:
str   The string to remove the character from.
pos   The position at which to remove the character. GStrings are zero indexed, just like regular C character arrays.

void g_string_escape_char ( GString * str,
gchar chr )
 

Backslash escape occurrances of characters within a string.

Sometimes characters need to be "backslash escaped" in order to be translated properly. For example if you want to put text containing single quotes into the text field of a database using SQL, you will need to backslash escape the single quotes.

 The following code snippet will produce a string that contains: 
 It\'s got\'s some single quotes, y\'all

 GString  *str;

 str = g_string_new ("It's got's some single quotes, y'all");
 g_string_escape_char (str, ''');
 
Parameters:
str   The string to work on.
chr   The character to escape in the string.

void g_string_insert_char ( GString * str,
gchar chr,
gint pos )
 

Insert a character into a string.

Insert a character into any spot within a string without overwritting the original contenets of the string. Chacters at and after the insert position are shifted to the right.

Parameters:
str   The string to be inserted into.
chr   The character to insert.
pos   The position within the string to insert the character. GStrings are zero indexed.

void g_string_insert_str ( GString * str1,
gchar * str2,
gint pos )
 

Insert a string into a string.

Insert a string into any spot within a string without overwritting the original contenets of the string. Chacters at and after the insert position are shifted to the right to make room for the string being inserted.

Parameters:
str1   The string to be inserted into.
str2   The string of characters to insert.
pos   The position within the string to insert the other string. GStrings are zero indexed.

void g_string_prepare_db_instr ( GString * str )
 

Prepare a SQL string for sending to the database.

Text data that is INSERT'ed or UPDATE'ed needs to be prepared before it can be used properly in an INSERT or UPDATE query. This function will strip any trailing white space, backslash escape any single quotes within the string, and surround the string with single quotes.

If the string is empty or all white space, this function will return the string "NULL" (no quotes).

 The following code snippet will produce a string that contains: 
 'It\'s got\'s some single quotes, y\'all'

 GString  *str;

 str = g_string_new ("It's got's some single quotes, y'all");
 g_string_prepare_db_instr (str);
 
Parameters:
str   The string that is to be prepared.

void g_string_prepare_html ( GString * str )
 

Prepare a string for use within an HTML document.

Text that is displayed on an HTML document will need to be prepared so that characters that are used as part of the HTML syntax are replaced by their HTML symbols. Also, newline characters need to be changed into '
' symbols, since all whitespace in HTML documents is treated as a single space.

  The following code snippet will produce a string that contins:
  This string has some &lt;special&gt; characters in it<br>dude.

  GString *str;

  str = g_string_new 
           ("This string has some <special> characters in it\ndude.");
  g_string_prepare_html (str);
  
Parameters:
str   The string that is to be prepared.

Returns:
Nothing.

GString * g_string_strip ( GString * str )
 

Strip the string of any trailing white spaces.

Parameters:
str   The string to remove the trailing spaces from.

Returns:
A pointer to the string that was passed in.


Generated at Sun Jan 7 09:55:03 2001 for libPRepS by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000