Skip to content

Commit 8e53178

Browse files
committed
Fixed issue #14: Allow generated code to only use octal representation for non-printable characters
1 parent c06c92e commit 8e53178

File tree

8 files changed

+290
-227
lines changed

8 files changed

+290
-227
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changes for 2.0:
55
* New feature: Command line --quiet to not output any message to standard output.
66
* New feature: Command line --baseclass to change the default name of the interface which is File
77
* Fixed issue #5: Remove the concept of segment
8+
* Fixed issue #14: Allow generated code to only use octal representation for non-printable characters
89
* Fixed issue #16: Implement a --namespace argument
910
* Fixed issue #17: Implement a --help and --h
1011
* Fixed issue #19: Add NSIS as a prerequisite in README and INSTALL

src/ArrayGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace bin2cpp
9696
}
9797

9898
//output
99-
fprintf(cpp, " %s", toCppCharactersArray(buffer, readSize).c_str());
99+
fprintf(cpp, " %s", cppencoder::toCppCharactersArray(buffer, readSize).c_str());
100100
numLinePrinted++;
101101
}
102102

src/SegmentGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace bin2cpp
9494
continue; //nothing to output if nothing was read
9595

9696
//output
97-
fprintf(cpp, " mBuffer.append(\"%s\", %d);\n", toCppString(buffer, readSize).c_str(), readSize);
97+
fprintf(cpp, " mBuffer.append(\"%s\", %d);\n", cppencoder::toOctString(buffer, readSize, false).c_str(), readSize);
9898
}
9999
delete[] buffer;
100100
buffer = NULL;

src/StringGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace bin2cpp
9696
}
9797

9898
//output
99-
fprintf(cpp, " \"%s\"", toCppString(buffer, readSize).c_str());
99+
fprintf(cpp, " \"%s\"", cppencoder::toOctString(buffer, readSize, false).c_str());
100100
numLinePrinted++;
101101
}
102102

src/common.cpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -230,34 +230,6 @@ namespace bin2cpp
230230
return BINCPP_VERSION;
231231
}
232232

233-
void toHexString(unsigned char c, unsigned char & c1, unsigned char & c2)
234-
{
235-
static const char * hexCharacters = "0123456789abcdef";
236-
c1 = hexCharacters[c/16];
237-
c2 = hexCharacters[c%16];
238-
}
239-
240-
void toOctString(unsigned char c, unsigned char & c1, unsigned char & c2, unsigned char & c3)
241-
{
242-
static const char * octCharacters = "01234567";
243-
c3 = octCharacters[c%8];
244-
c /= 8;
245-
c2 = octCharacters[c%8];
246-
c /= 8;
247-
c1 = octCharacters[c];
248-
}
249-
250-
bool isPrintableCharacter(const char c)
251-
{
252-
if (c == 39) // character ' must be escaped with \' which is not supported right now
253-
return false;
254-
if (c == 92) // character \ must be escaped with \\ which is not supported right now
255-
return false;
256-
if (c >= 32 && c<= 126)
257-
return true;
258-
return false;
259-
}
260-
261233
std::string getParentPath(const std::string & iPath)
262234
{
263235
std::string parent;
@@ -276,42 +248,6 @@ namespace bin2cpp
276248

277249
void splitPath(const std::string & iPath, std::string & oFolder, std::string & oFilename)
278250
{
279-
//char separator = getPathSeparator();
280-
281-
////reset everything
282-
//oFilename = "";
283-
//oFolder = "";
284-
285-
////start from the end and capture each character into oFilename
286-
//bool wDumpingInFilename = true;
287-
//for(int i = iPath.size() - 1; i >= 0; i--)
288-
//{
289-
// char c = iPath[i];
290-
// if (c == separator && wDumpingInFilename)
291-
// {
292-
// wDumpingInFilename = false;
293-
// }
294-
295-
// //decide where the character will be dumped
296-
// std::string * wDestination = NULL;
297-
// if (wDumpingInFilename)
298-
// {
299-
// wDestination = &oFilename;
300-
// }
301-
// else
302-
// {
303-
// wDestination = &oFolder;
304-
// }
305-
306-
// //dump c into destination string
307-
// wDestination->insert(0, 1, c);
308-
//}
309-
310-
//if (oFolder.size() == 0)
311-
//{
312-
// oFolder = std::string(".") + separator;
313-
//}
314-
315251
oFolder = "";
316252
oFilename = "";
317253

src/common.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,6 @@ namespace bin2cpp
7474
*/
7575
const char * getVersionString();
7676

77-
///<summary>
78-
///Converts a single byte character to the two characters representing this byte in hexadicimal.
79-
///For instance, toHexString(64, c1, c2) assigns c1='4' and c2='0'
80-
///</summary>
81-
///<param name="c">The input byte value</param>
82-
///<param name="c1">The first character of the hexadecimal string.</param>
83-
///<param name="c2">The second character of the hexadecimal string.</param>
84-
///<return>The the two characters representing the hexadecimal value of c.<return>
85-
void toHexString(unsigned char c, unsigned char & c1, unsigned char & c2);
86-
87-
///<summary>
88-
///Converts a single byte character to the 3 characters representing this byte in octal.
89-
///For instance, toOctString(83, c1, c2, c3) assigns c1='1', c2='2' and c3='3'
90-
///</summary>
91-
///<param name="c">The input byte value</param>
92-
///<param name="c1">The first character of the octal string.</param>
93-
///<param name="c2">The second character of the octal string.</param>
94-
///<param name="c3">The third character of the octal string.</param>
95-
///<return>The the two characters representing the hexadecimal value of c.<return>
96-
void toOctString(unsigned char c, unsigned char & c1, unsigned char & c2, unsigned char & c3);
97-
98-
///<summary>
99-
///Returns true if the given character is printable to a console.
100-
///</summary>
101-
///<param name="c">The input character value</param>
102-
///<return>Returns true if the given character is printable to a console.<return>
103-
bool isPrintableCharacter(const char c);
104-
10577
///<summary>
10678
///Returns the parent element of a path. For files, returns the file's directory. For folders, returns the parent path
10779
///</summary>

0 commit comments

Comments
 (0)