2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <ZLApplication.h>
24 #include <ZLStringUtil.h>
28 bool MiscUtil::isReference(const std::string
&text
) {
30 ZLStringUtil::stringStartsWith(text
, "http://") ||
31 ZLStringUtil::stringStartsWith(text
, "https://") ||
32 ZLStringUtil::stringStartsWith(text
, "mailto:") ||
33 ZLStringUtil::stringStartsWith(text
, "ftp://");
36 std::string
MiscUtil::htmlDirectoryPrefix(const std::string
&fileName
) {
37 ZLFile
file(fileName
);
38 std::string shortName
= file
.name(false);
39 std::string path
= file
.path();
41 if ((path
.length() > shortName
.length()) &&
42 (path
[path
.length() - shortName
.length() - 1] == ':')) {
43 index
= shortName
.rfind('/');
45 return path
.substr(0, path
.length() - shortName
.length() + index
+ 1);
48 std::string
MiscUtil::htmlFileName(const std::string
&fileName
) {
49 ZLFile
file(fileName
);
50 std::string shortName
= file
.name(false);
51 std::string path
= file
.path();
53 if ((path
.length() > shortName
.length()) &&
54 (path
[path
.length() - shortName
.length() - 1] == ':')) {
55 index
= shortName
.rfind('/');
57 return path
.substr(path
.length() - shortName
.length() + index
+ 1);
60 std::string
MiscUtil::decodeHtmlURL(const std::string
&encoded
) {
65 const int len
= encoded
.length();
67 for (int i
= 0; i
< len
; i
++) {
68 if ((encoded
[i
] == '%') && (i
< len
- 2)) {
69 buffer
[0] = *(encoded
.data() + i
+ 1);
70 buffer
[1] = *(encoded
.data() + i
+ 2);
71 decoded
+= (char)strtol(buffer
, 0, 16);
74 decoded
+= encoded
[i
];