forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_style_check_reader.cpp
65 lines (62 loc) · 2.58 KB
/
text_style_check_reader.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
#include "generic_factory.h"
#include "text_style_check.h"
text_style_check_reader::text_style_check_reader( const allow_object object_allowed )
: object_allowed( object_allowed )
{
}
std::string text_style_check_reader::get_next( JsonValue jv ) const
{
const JsonValue &jsin = jv;
std::string raw;
bool check_style = true;
if( object_allowed == allow_object::yes && jsin.test_object() ) {
JsonObject jsobj = jsin.get_object();
raw = jsobj.get_string( "str" );
if( jsobj.has_member( "//NOLINT(cata-text-style)" ) ) {
check_style = false;
}
} else {
raw = jsin.get_string();
}
#ifndef CATA_IN_TOOL
if( test_mode && check_style ) {
const auto text_style_callback =
[&jsin]
( const text_style_fix type, const std::string & msg,
const std::u32string::const_iterator & beg, const std::u32string::const_iterator & /*end*/,
const std::u32string::const_iterator & /*at*/,
const std::u32string::const_iterator & from, const std::u32string::const_iterator & to,
const std::string & fix
) {
std::string err;
switch( type ) {
case text_style_fix::removal:
err = msg + "\n"
+ " Suggested fix: remove \"" + utf32_to_utf8( std::u32string( from, to ) ) + "\"\n"
+ " At the following position (marked with caret)";
break;
case text_style_fix::insertion:
err = msg + "\n"
+ " Suggested fix: insert \"" + fix + "\"\n"
+ " At the following position (marked with caret)";
break;
case text_style_fix::replacement:
err = msg + "\n"
+ " Suggested fix: replace \"" + utf32_to_utf8( std::u32string( from, to ) )
+ "\" with \"" + fix + "\"\n"
+ " At the following position (marked with caret)";
break;
}
try {
jsin.string_error( err, std::distance( beg, to ) );
} catch( const JsonError &e ) {
debugmsg( "(json-error)\n%s", e.what() );
}
};
const std::u32string raw32 = utf8_to_utf32( raw );
text_style_check<std::u32string::const_iterator>( raw32.cbegin(), raw32.cend(),
fix_end_of_string_spaces::yes, escape_unicode::no, text_style_callback );
}
#endif
return raw;
}