~ubuntu-branches/ubuntu/wily/csstidy/wily

« back to all changes in this revision

Viewing changes to csstidy/trim.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Coyner
  • Date: 2008-02-24 20:52:52 UTC
  • mfrom: (2.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20080224205252-i9t0wyrnjeedczz2
Tags: 1.4-3
* Add patch gcc43fix which contains an uncaught missing include in
  csstidy/misc.cpp. Closes: #455123.
* Bumped Standards-Version to 3.7.3. No changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of CSSTidy.
 
3
 *
 
4
 * CSSTidy is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * CSSTidy is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with CSSTidy; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 */
 
18
 
 
19
#include "csspp_globals.hpp"
 
20
using namespace std;
 
21
 
 
22
const string trim(const string istring)
 
23
{
 
24
        std::string::size_type first = istring.find_first_not_of(" \n\t\r\0xb");
 
25
        if (first == std::string::npos) {
 
26
                return std::string();
 
27
        }
 
28
        else {
 
29
                std::string::size_type last = istring.find_last_not_of(" \n\t\r\0xb");
 
30
                return istring.substr( first, last - first + 1);
 
31
        }
 
32
}
 
33
 
 
34
const string ltrim(const string istring)
 
35
{
 
36
        std::string::size_type first = istring.find_first_not_of(" \n\t\r\0xb");
 
37
        if (first == std::string::npos) {
 
38
                return std::string();
 
39
        }
 
40
        else {
 
41
                return istring.substr( first );
 
42
        }
 
43
}
 
44
 
 
45
 
 
46
const string rtrim(const string istring)
 
47
{
 
48
        std::string::size_type last = istring.find_last_not_of(" \n\t\r\0xb"); /// must succeed
 
49
        return istring.substr( 0, last + 1);
 
50
}
 
51
 
 
52
const string rtrim(const string istring, const string chars)
 
53
{
 
54
        std::string::size_type last = istring.find_last_not_of(chars); /// must succeed
 
55
        return istring.substr( 0, last + 1);
 
56
}
 
57
 
 
58
string strip_tags(string istring)
 
59
{
 
60
        bool intag = false;
 
61
        string new_string;
 
62
                
 
63
        for(int i = 0; i < istring.length(); i++)
 
64
        {
 
65
                if(istring[i] != '<' && !intag)
 
66
                {
 
67
                        new_string += istring[i];
 
68
                }
 
69
                if(istring[i] == '<' && !intag)
 
70
                {
 
71
                        intag = true;
 
72
                }
 
73
                if(istring[i] == '>' && intag)
 
74
                {
 
75
                        intag = false;
 
76
                }                       
 
77
        }
 
78
        return new_string;
 
79
}