From 9a21d52d0b5ae8f7e82ce531779991bd1f9e297b Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Mon, 24 Jul 2006 08:25:55 +0000 Subject: [PATCH] Replace invalid utf-8 characters with underscores. Bump cache version. --- stepmania/src/Song.cpp | 2 +- stepmania/src/SongCacheIndex.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 3ac10286cd..5596d834c3 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -34,7 +34,7 @@ #include #include -const int FILE_CACHE_VERSION = 145; // increment this to invalidate cache +const int FILE_CACHE_VERSION = 146; // increment this to invalidate cache const float DEFAULT_MUSIC_SAMPLE_LENGTH = 12.f; diff --git a/stepmania/src/SongCacheIndex.cpp b/stepmania/src/SongCacheIndex.cpp index d4d43298f0..7031e59986 100644 --- a/stepmania/src/SongCacheIndex.cpp +++ b/stepmania/src/SongCacheIndex.cpp @@ -34,8 +34,16 @@ RString SongCacheIndex::GetCacheFilePath( const RString &sGroup, const RString & /* Don't use GetHashForFile, since we don't want to spend time * checking the file size and date. */ RString s = sPath; - s.Replace( '/', '_' ); - return ssprintf( "%s/%s/%s", SpecialFiles::CACHE_DIR.c_str(), sGroup.c_str(), s.c_str() ); + /* Change slashes and invalid utf-8 characters to _. + * http://en.wikipedia.org/wiki/UTF-8 + * Mac OS X doesn't support precomposed unicode characters in files names and + * so we should probably replace them with combining diacritics. + * XXX How do we do this and is it even worth it? */ + const char *invalid = "/\xc0\xc1\xfe\xff\xf8\xf9\xfa\xfb\xfc\xfd\xf5\xf6\xf7"; + for( size_t pos = s.find_first_of(invalid); pos != RString::npos; pos = s.find_first_of(invalid, pos) ) + s[pos] = '_'; + // CACHE_DIR ends with a /. + return ssprintf( "%s%s/%s", SpecialFiles::CACHE_DIR.c_str(), sGroup.c_str(), s.c_str() ); } SongCacheIndex::SongCacheIndex()