aboutsummaryrefslogtreecommitdiff
path: root/src/encoding.cc
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <benjamin@barenblat.name>2018-06-20 17:55:59 -0400
committerGravatar Benjamin Barenblat <benjamin@barenblat.name>2018-06-20 18:02:14 -0400
commit332bd4d47cee71961e5ba2975ce502e7b6f30e6d (patch)
treea23fb7a37b229e6d887bf27a979985f18f8267c5 /src/encoding.cc
parent3ecfa37a00dd9a7a06ca572853f52e71c4f66e66 (diff)
Support files ending in spaces or periods
In addition to the characters Scoville already handles, FAT also disallows space and period as the last character in a file name. Convert trailing space and period to the relevant escape sequences. Closes: https://github.com/bbarenblat/scoville/issues/2
Diffstat (limited to 'src/encoding.cc')
-rw-r--r--src/encoding.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/encoding.cc b/src/encoding.cc
index 3cd29a8..702b2c4 100644
--- a/src/encoding.cc
+++ b/src/encoding.cc
@@ -1,4 +1,4 @@
-// Copyright 2016 Benjamin Barenblat
+// Copyright 2016, 2018 Benjamin Barenblat
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
@@ -53,10 +53,18 @@ bool IsVfatBadCharacter(const char c) noexcept {
c == '|' || c == '"' || c == ':' || c == '\\';
}
+bool IsVfatBadLastCharacter(const char c) noexcept {
+ return IsVfatBadCharacter(c) || c == '.' || c == ' ';
+}
+
void EncodeStream(std::istringstream* const in, std::ostringstream* const out) {
char c;
while (!in->get(c).eof()) {
- if (IsVfatBadCharacter(c)) {
+ in->peek();
+ const bool processing_last_character = in->eof();
+
+ if (IsVfatBadCharacter(c) ||
+ (processing_last_character && IsVfatBadLastCharacter(c))) {
*out << '%';
WriteAsciiAsHex(c, out);
} else if (c == '%') {