2 * Copyright (C) 2007, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "FileSystem.h"
29 #include <wtf/HexNumber.h>
33 // The following lower-ASCII characters need escaping to be used in a filename
34 // across all systems, including Windows:
35 // - Unprintable ASCII (00-1F)
37 // - Double quote (22)
38 // - Percent (25) (escaped because it is our escape character)
43 // - Greater-than (3E)
44 // - Question Mark (3F)
49 static const bool needsEscaping[128] = {
50 /* 00-07 */ true, true, true, true, true, true, true, true,
51 /* 08-0F */ true, true, true, true, true, true, true, true,
53 /* 10-17 */ true, true, true, true, true, true, true, true,
54 /* 18-1F */ true, true, true, true, true, true, true, true,
56 /* 20-27 */ true, false, true, false, false, true, false, false,
57 /* 28-2F */ false, false, true, false, false, false, false, true,
59 /* 30-37 */ false, false, false, false, false, false, false, false,
60 /* 38-3F */ false, false, true, false, true, false, true, true,
62 /* 40-47 */ false, false, false, false, false, false, false, false,
63 /* 48-4F */ false, false, false, false, false, false, false, false,
65 /* 50-57 */ false, false, false, false, false, false, false, false,
66 /* 58-5F */ false, false, false, false, true, false, false, false,
68 /* 60-67 */ false, false, false, false, false, false, false, false,
69 /* 68-6F */ false, false, false, false, false, false, false, false,
71 /* 70-77 */ false, false, false, false, false, false, false, false,
72 /* 78-7F */ false, false, false, false, true, false, false, true,
75 static inline bool shouldEscapeUChar(UChar c)
77 return c > 127 ? false : needsEscaping[c];
80 String encodeForFileName(const String& inputStr)
82 unsigned length = inputStr.length();
83 Vector<UChar, 512> buffer(length * 3 + 1);
84 UChar* p = buffer.data();
86 const UChar* str = inputStr.characters();
87 const UChar* strEnd = str + length;
89 while (str < strEnd) {
91 if (shouldEscapeUChar(c)) {
98 ASSERT(p - buffer.data() <= static_cast<int>(buffer.size()));
100 return String(buffer.data(), p - buffer.data());
105 bool canExcludeFromBackup()
110 bool excludeFromBackup(const String&)
117 } // namespace WebCore