• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 // -*- c++ -*-
19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
20 
21 //               O S C L _ S T R I N G _ X M L
22 
23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
24 
25 /*! \addtogroup osclutil OSCL Util
26  *
27  * @{
28  */
29 
30 
31 /** \file oscl_string_xml.h
32     \brief Utilities to escape special characters in XML strings
33 */
34 
35 
36 /*!
37  * \par XML String Manipualation
38  * These routines handle the special characters, which needs to be escaped, for xml document.
39  *
40  */
41 #ifndef OSCL_STRING_XML_H
42 #define OSCL_STRING_XML_H
43 
44 // - - Inclusion - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45 #ifndef OSCL_BASE_H_INCLUDED
46 #include "oscl_base.h"
47 #endif
48 
49 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 // Function prototypes
51 /*!
52     \brief Check if the input string contains any special ASCII character
53            like &, <, >, ', ".
54            The function scans the string and check if each character is a special character.
55            It stops at the first NULL character (if max_bytes = 0), or the max_byte value.
56 
57     \param str_buf          Ptr to an input string, which may not terminate with null, to be checked
58     \param num_escape_bytes This is an output parameter which is the number of bytes needed to hold
59                             the result string.
60                             Value 0 indicates that there is no special character found.
61                             If max_bytes = 0, the return value does not include the null character.
62     \param max_bytes        The maximum number of bytes to read (a zero value means read to the first NULL character).
63     \return                 True if the function succeeds, and
64                             num_escape_bytes = 0 means that no special character is found,
65                             num_escape_bytes >0 means the number of bytes of the result string.
66                             False if there is any error occurred.
67 */
68 OSCL_IMPORT_REF bool  oscl_str_need_escape_xml(const char *str_buf, uint32& num_escape_bytes, uint32 max_bytes = 0);
69 /*!
70     \brief Escape any of the following special characters in the string
71            Special ASCII characters: &, <, >, ', ".
72 
73            The function scans the string and replaces each special character with its corresponding
74            escape sequence. It stops at the first NULL character, the max_byte value.
75 
76     \param str_buf_in       Ptr to an input string
77     \param str_buf_out      Ptr to an output buffer which stores the modified string
78     \param max_out_buf_bytes The size of str_buf_out.
79     \param max_bytes        The maximum number of bytes to read (a zero value means read to the first NULL character).
80                             It is the length of str_buf_in.
81     \param num_bytes_written Number of bytes written in the output buffer, str_buf_out
82     \return                 It returns the number of bytes in the str_buf_outring if succeeded.
83                             It returns negative number if failed, and its absolute value indicates
84                             the total number bytes written to the output buffer, str_buf_out,
85                             if str_buf_out != null.
86 */
87 OSCL_IMPORT_REF int32  oscl_str_escape_xml(const char *str_buf_in, char *str_buf_out, uint32 max_out_buf_bytes, uint32 max_bytes = 0,
88         uint32 * num_bytes_written = NULL);
89 #endif
90 
91 
92 /*! @} */
93