Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - ssrc/wispers/utility - WebStrings.h (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 35 35 100.0 %
Date: 2012-04-09 Functions: 10 10 100.0 %
Branches: 5 10 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2006-2009 Savarese Software Research Corporation
       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                 :            :  *     https://www.savarese.com/software/ApacheLicense-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 express or implied.
      13                 :            :  * See the License for the specific language governing permissions and
      14                 :            :  * limitations under the License.
      15                 :            :  */
      16                 :            : 
      17                 :            : #ifndef __SSRC_WSPR_UTILITY_WEB_STRINGS_H
      18                 :            : #define __SSRC_WSPR_UTILITY_WEB_STRINGS_H
      19                 :            : 
      20                 :            : #include <ssrc/wispers-packages.h>
      21                 :            : 
      22                 :            : #include <string>
      23                 :            : #include <tuple>
      24                 :            : 
      25                 :            : __BEGIN_NS_SSRC_WSPR_UTILITY
      26                 :            : 
      27                 :            : using std::string;
      28                 :            : 
      29                 :            : void escape_javascript(string & result, const char *text,
      30                 :            :                        const unsigned int text_size);
      31                 :            : 
      32                 :          1 : inline void escape_javascript(string & result, const string & text) {
      33                 :          1 :   escape_javascript(result, text.c_str(), text.size());
      34                 :          1 : }
      35                 :            : 
      36                 :          1 : inline string escape_javascript(const string & text) {
      37                 :          1 :   string result;
      38         [ +  - ]:          1 :   escape_javascript(result, text);
      39                 :          1 :   return result;
      40                 :            : }
      41                 :            : 
      42                 :            : void escape_html(string & result, const char *text,
      43                 :            :                  const unsigned int text_size);
      44                 :            : 
      45                 :          1 : inline void escape_html(string & result, const string & text) {
      46                 :          1 :   escape_html(result, text.c_str(), text.size());
      47                 :          1 : }
      48                 :            : 
      49                 :          1 : inline string escape_html(const string & text) {
      50                 :          1 :   string result;
      51         [ +  - ]:          1 :   escape_html(result, text);
      52                 :          1 :   return result;
      53                 :            : }
      54                 :            : 
      55                 :            : void escape_url(string & result, const char *text,
      56                 :            :                 const unsigned int text_size);
      57                 :            : 
      58                 :          1 : inline void escape_url(string & result, const string & text) {
      59                 :          1 :   escape_url(result, text.c_str(), text.size());
      60                 :          1 : }
      61                 :            : 
      62                 :          1 : inline string escape_url(const string & text) {
      63                 :          1 :   string result;
      64         [ +  - ]:          1 :   escape_url(result, text);
      65                 :          1 :   return result;
      66                 :            : }
      67                 :            : 
      68                 :            : void unescape_url(string & url);
      69                 :            : 
      70                 :            : void strip_html(string & result, const char *text,
      71                 :            :                 const unsigned int text_size);
      72                 :            : 
      73                 :          2 : inline void strip_html(string & result, const string & text) {
      74                 :          2 :   strip_html(result, text.c_str(), text.size());
      75                 :          2 : }
      76                 :            : 
      77                 :          2 : inline string strip_html(const string & text) {
      78                 :          2 :   string result;
      79         [ +  - ]:          2 :   strip_html(result, text);
      80                 :          2 :   return result;
      81                 :            : }
      82                 :            : 
      83                 :            : void strip_html_and_unescape(string & result, const char *text,
      84                 :            :                              const unsigned int text_size);
      85                 :            : 
      86                 :            : inline string strip_html_and_unescape(const char *text,
      87                 :            :                                       const unsigned int text_size)
      88                 :            : {
      89                 :            :   string result;
      90                 :            :   strip_html_and_unescape(result, text, text_size);
      91                 :            :   return result;
      92                 :            : }
      93                 :            : 
      94                 :          1 : inline void strip_html_and_unescape(string & result, const string & text) {
      95                 :          1 :   strip_html_and_unescape(result, text.c_str(), text.size());
      96                 :          1 : }
      97                 :            : 
      98                 :          1 : inline string strip_html_and_unescape(const string & text) {
      99                 :          1 :   string result;
     100         [ +  - ]:          1 :   strip_html_and_unescape(result, text);
     101                 :          1 :   return result;
     102                 :            : }
     103                 :            : 
     104                 :            : void wrap_lines(char *text, const unsigned int text_size,
     105                 :            :                 const unsigned int max_length = 79);
     106                 :            : 
     107                 :            : typedef
     108                 :            : std::tuple<const char *, std::ptrdiff_t, const char *, std::ptrdiff_t>
     109                 :            : title_body_type;
     110                 :            : 
     111                 :            : title_body_type html_title_and_body(const char *begin, const char *end);
     112                 :            : 
     113                 :            : __END_NS_SSRC_WSPR_UTILITY
     114                 :            : 
     115                 :            : #endif