This repository was archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.cpp
More file actions
109 lines (92 loc) · 2.98 KB
/
util.cpp
File metadata and controls
109 lines (92 loc) · 2.98 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "util.h"
#include "coding_functions.h"
#include <string>
#include <iostream>
bool errorOnDisallowedChars( const std::string & type, const std::string & invalidChars )
{
if( !invalidChars.empty() ) {
std::string name = getNames()[ type ];
if( name.size() > 0 ) {
std::cout << "Invalid characters in `" << name << "' section: " << invalidChars << ", they are skipped" << std::endl;
} else {
std::cout << "Invalid characters used: " << invalidChars << ", they are skipped" << std::endl;
}
return true;
}
return false;
}
void PresentData(
std::string & protocol,
std::string & user,
std::string & site,
std::string & port,
std::string & repo,
std::string & rev,
std::string & file
) {
std::cout << GREEN "Protocol:" RESET " " << protocol << std::endl;
if ( user.size() > 0 )
std::cout << GREEN "User:" RESET " " << user << std::endl;
std::cout << GREEN "Site:" RESET " " << site << std::endl;
if ( port.size() > 0 )
std::cout << GREEN "Port:" RESET " " << port << std::endl;
std::cout << YELLOW "Repo:" RESET " " << repo << std::endl;
if ( rev.size() > 0 )
std::cout << YELLOW "Revision:" RESET " " << rev << std::endl;
if ( file.size() > 0 )
std::cout << RED "File:" RESET " " << file << std::endl;
}
void PresentURL(
std::string & protocol,
std::string & user,
std::string & site,
std::string & port,
std::string & repo,
std::string & rev,
std::string & file,
bool extended,
bool noansi
) {
std::string out = protocol;
out += "://" + site;
if ( port.size() > 0 )
out += ":" + port;
out += "/" + repo;
if ( extended ) {
if ( noansi == false )
std::cout << MAGENTA;
std::cout << out;
if ( rev.size() > 0 )
std::cout << " / rev:" << rev;
if ( file.size() > 0 )
std::cout << " / file:" << file;
if ( noansi == false )
std::cout << RESET;
std::cout << std::endl;
} else {
if ( noansi == false ) {
std::cout << MAGENTA << out << RESET << std::endl;
} else {
std::cout << out << std::endl;
}
}
}
const char* single_to_narrow( wchar_t inchar ) {
wchar_t input_buffer[ 2 ] = { inchar, L'\0' };
static char output_buffer[ 8 ];
if( (size_t)-1 == wcstombs ( output_buffer, input_buffer, sizeof(output_buffer) ) ) {
output_buffer[0] = '\0';
}
return output_buffer;
}
const char* wide_to_narrow( wchar_t *input_buffer, int size ) {
static char output_buffer[ 65536 ];
wchar_t newbuf[size+1];
std::wcsncpy( newbuf, input_buffer, size );
newbuf[ size ] = L'\0';
if( (size_t)-1 == wcstombs ( output_buffer, newbuf, 65536 ) ) {
output_buffer[0] = '\0';
}
output_buffer[65535] = '\0';
return output_buffer;
}