Debug output to the log stream instead of cerr.
[gnucomo.git] / src / gcm_input / string_utils.cpp
1
2 /**************************************************************************
3 **  (c) Copyright 2003, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************
7 ** MODULE INFORMATION *
8 ***********************
9 **      FILE NAME      : string_utils.cpp
10 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
11 **      VERSION NUMBER : $Revision: 1.1 $
12 **
13 **  DESCRIPTION      :  Utility functions for Strings
14 **
15 **  EXPORTED OBJECTS : 
16 **  LOCAL    OBJECTS : 
17 **  MODULES  USED    :
18 ***************************************************************************
19 **  ADMINISTRATIVE INFORMATION *
20 ********************************
21 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 **      CREATION DATE   : Jul 31, 2003
23 **      LAST UPDATE     : Jul 31, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: string_utils.cpp,v $
29    Revision 1.1  2003-08-05 08:15:01  arjen
30    Debug output to the log stream instead of cerr.
31    Fixed namespace problems in XPath searches of the DOM.
32    Moved string utility functions to a separate file.
33
34 *****************************/
35
36 static const char *RCSID = "$Id: string_utils.cpp,v 1.1 2003-08-05 08:15:01 arjen Exp $";
37
38 #include <AXE/String.h>
39
40 /*=========================================================================
41 **  NAME           : SQL_Escape
42 **  SYNOPSIS       : String SQL_Escape(String)
43 **  PARAMETERS     : 
44 **  RETURN VALUE   : 
45 **
46 **  DESCRIPTION    : Insert backslashes before single quotes.
47 **
48 **  VARS USED      :
49 **  VARS CHANGED   :
50 **  FUNCTIONS USED :
51 **  SEE ALSO       :
52 **  LAST MODIFIED  : 
53 **=========================================================================
54 */
55
56 String SQL_Escape(String s)
57 {
58    int i;
59
60    for (i = 0; i < ~s; i++)
61    {
62       if (s[i] == '\'')
63       {
64          s(i,0) = "\\";
65          i++;
66       }
67    }
68
69    return s;
70 }
71
72 /*=========================================================================
73 **  NAME           : XML_Entities
74 **  SYNOPSIS       : String XML_Entities(String)
75 **  PARAMETERS     : 
76 **  RETURN VALUE   : 
77 **
78 **  DESCRIPTION    : Replace special characters for XML with their entity codes:
79 **                          "<"  =>   "&lt;"
80 **                          ">"  =>   "&gt;"
81 **                          "&"  =>   "&amp;"
82 **
83 **  VARS USED      :
84 **  VARS CHANGED   :
85 **  FUNCTIONS USED :
86 **  SEE ALSO       :
87 **  LAST MODIFIED  : 
88 **=========================================================================
89 */
90
91 String XML_Entities(String s)
92 {
93    int i;
94
95    for (i = 0; i < ~s; i++)
96    {
97       switch (s[i])
98       {
99       case '&':
100          s(i,1) = "&amp;";
101          i++;
102          break;
103       case '<':
104          s(i,1) = "&lt;";
105          i++;
106          break;
107       case '>':
108          s(i,1) = "&gt;";
109          i++;
110          break;
111       }
112    }
113
114    return s;
115 }