From 332bd4d47cee71961e5ba2975ce502e7b6f30e6d Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Wed, 20 Jun 2018 17:55:59 -0400 Subject: 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 --- src/encoding.cc | 12 ++++++++++-- 1 file 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 == '%') { -- cgit v1.2.3