From 998d8f4e7abe87ebc8df91698265da0b343e8394 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 7 May 2013 23:49:47 -0500 Subject: [PATCH] Use standard unicode forward slash representation if available instead of nonstandard HTML encoding This resolves Bug 269 (cherry picked from commit b4a23465b612356d94db0f66fc728b90dc3d0dca) --- kio/kio/global.cpp | 39 +++++++++++++++++++++++++++++---------- kio/kio/global.h | 6 +++--- kioslave/file/file.cc | 3 ++- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/kio/kio/global.cpp b/kio/kio/global.cpp index f99219524..927f04a88 100644 --- a/kio/kio/global.cpp +++ b/kio/kio/global.cpp @@ -165,41 +165,60 @@ KIO_EXPORT TQString KIO::itemsSummaryString(uint items, uint files, uint dirs, K KIO_EXPORT TQString KIO::encodeFileName( const TQString & _str ) { TQString str( _str ); + bool unicode_supported = (TQString::fromLocal8Bit(TQString(TQChar((uint)0x2215)).local8Bit())[0].unicode() != 0x3f); int i = 0; - while ( ( i = str.find( "%", i ) ) != -1 ) - { + while ( ( i = str.find( "%", i ) ) != -1 ) { str.replace( i, 1, "%%"); i += 2; } - while ( ( i = str.find( "/" ) ) != -1 ) - str.replace( i, 1, "%2f"); + while ( ( i = str.find( "/" ) ) != -1 ) { + if (unicode_supported) { + // Use U+2215 (DIVISION SLASH) to represent the forward slash + // While U+2044 (FRACTION SLASH) is a tempting replacement, it can indicate to + // rendering engines that a combined fraction character should be displayed + str.replace( i, 1, TQChar((uint)0x2215)); + } + else { + // Unicode does not appear to be supported on this system! + // Fall back to older encoding method... + str.replace( i, 1, "%2f"); + } + + str.replace( i, 1, TQChar((uint)0x2215)); + } return str; } KIO_EXPORT TQString KIO::decodeFileName( const TQString & _str ) { TQString str; + bool unicode_supported = (TQString::fromLocal8Bit(TQString(TQChar((uint)0x2215)).local8Bit())[0].unicode() != 0x3f); unsigned int i = 0; - for ( ; i < _str.length() ; ++i ) - { - if ( _str[i]=='%' ) - { + for ( ; i < _str.length() ; ++i ) { + if ( _str[i]=='%' ) { if ( _str[i+1]=='%' ) // %% -> % { str.append('%'); ++i; } - else if ( _str[i+1]=='2' && (i+2<_str.length()) && _str[i+2].lower()=='f' ) // %2f -> / + else if ((!unicode_supported) && ( _str[i+1]=='2' && (i+2<_str.length()) && _str[i+2].lower()=='f' )) // %2f -> / { str.append('/'); i += 2; } else + { str.append('%'); - } else + } + } + else if ( _str[i] == TQChar((uint)0x2215) ) { + str.append('/'); + } + else { str.append(_str[i]); + } } return str; diff --git a/kio/kio/global.h b/kio/kio/global.h index 03fb61dcc..ef996a584 100644 --- a/kio/kio/global.h +++ b/kio/kio/global.h @@ -118,7 +118,7 @@ namespace KIO /** * Encodes (from the text displayed to the real filename) - * This translates % into %% and / into %2f + * This translates % into %% and / into ∕ (U+2215, DIVISION SLASH) * Used by KIO::link, for instance. * @param str the file name to encode * @return the encoded file name @@ -126,7 +126,7 @@ namespace KIO KIO_EXPORT TQString encodeFileName( const TQString & str ); /** * Decodes (from the filename to the text displayed) - * This translates %2[fF] into / and %% into % + * This translates %2[fF] into /, %% into %, and ∕ (U+2215, DIVISION SLASH) into / * @param str the file name to decode * @return the decoded file name */ @@ -501,7 +501,7 @@ public: }; /** - * An entry is the list of atoms containing all the informations for a file or URL + * An entry is the list of atoms containing all the information for a file or URL */ typedef TQValueList UDSEntry; typedef TQValueList UDSEntryList; diff --git a/kioslave/file/file.cc b/kioslave/file/file.cc index e33260b4b..79904bb50 100644 --- a/kioslave/file/file.cc +++ b/kioslave/file/file.cc @@ -1222,8 +1222,9 @@ void FileProtocol::listDir( const KURL& url) // files where TQFile::encodeName(TQFile::decodeName(a)) != a. TQStrList entryNames; - while ( ( ep = KDE_readdir( dp ) ) != 0L ) + while ( ( ep = KDE_readdir( dp ) ) != 0L ) { entryNames.append( ep->d_name ); + } closedir( dp ); totalSize( entryNames.count() );