1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*
* Filter tabs -> spaces.
*
* Author: Jan Holesovsky <kendy@suse.cz>
* License: MIT <http://www.opensource.org/licenses/mit-license.php>
*/
#ifndef _FILTER_HXX_
#define _FILTER_HXX_
#include <string>
#include <ostream>
enum FilterType {
NO_FILTER, ///< No filtering at all
FILTER_OLD, ///< Old way of filtering - each tab is exactly <n> spaces, no filtering after 1st non-tab, non-space character
FILTER_COMBINED, ///< Combined way of filtering - for the tabs before 1st non-tab, non-space character, behave like _OLD, for the rest as _TABS
FILTER_DOS, ///< Convert to the DOS line ends
FILTER_UNX, ///< Convert to the Unx line ends
FILTER_ALL ///< New way of filtering - each tab is converted as if it was a real tab + strip trailing whitespace
};
class Filter
{
std::string data;
/// This filter adds considers a tab this amount of spaces.
int spaces;
/// Current column in the output (resets with every \n).
int column;
/// In order to strip trailing spaces, we do not write them immediately.
int spaces_to_write;
/// Needed for the 'old' and 'combined' types
bool nonspace_appeared;
FilterType type;
public:
Filter( const std::string& fname_ );
void addData( const char* data_, size_t len_ );
void addData( const std::string& data_ );
void write( std::ostream& out_ );
static void addTabsToSpaces( int how_many_spaces_, FilterType type_, const std::string& files_regex_ );
};
#endif // _FILTER_HXX_
|