1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-11 23:54:18 +00:00

Avoided a false assertion in File. Minor clean-ups.

This commit is contained in:
jules 2013-09-10 15:11:20 +01:00
parent fc5fc50ae0
commit 14cfa338b6
5 changed files with 45 additions and 47 deletions

View file

@ -42,6 +42,7 @@ protected:
public:
//==============================================================================
virtual bool isRoot() const { return false; }
virtual bool acceptsFileDrop (const StringArray& files) const = 0;
virtual bool acceptsDragItems (const OwnedArray <Project::Item>& selectedNodes) = 0;

View file

@ -26,8 +26,7 @@
==============================================================================
*/
JNIClassBase::JNIClassBase (const char* classPath_)
: classPath (classPath_), classRef (0)
JNIClassBase::JNIClassBase (const char* cp) : classPath (cp), classRef (0)
{
getClasses().add (this);
}
@ -129,8 +128,7 @@ AndroidSystem::AndroidSystem() : screenWidth (0), screenHeight (0), dpi (160)
{
}
void AndroidSystem::initialise (JNIEnv* env, jobject activity_,
jstring appFile_, jstring appDataDir_)
void AndroidSystem::initialise (JNIEnv* env, jobject act, jstring file, jstring dataDir)
{
screenWidth = screenHeight = 0;
dpi = 160;
@ -141,9 +139,9 @@ void AndroidSystem::initialise (JNIEnv* env, jobject activity_,
systemInitialised = true;
#endif
activity = GlobalRef (activity_);
appFile = juceString (env, appFile_);
appDataDir = juceString (env, appDataDir_);
activity = GlobalRef (act);
appFile = juceString (env, file);
appDataDir = juceString (env, dataDir);
}
void AndroidSystem::shutdown (JNIEnv* env)
@ -162,14 +160,12 @@ AndroidSystem android;
//==============================================================================
namespace AndroidStatsHelpers
{
//==============================================================================
#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \
STATICMETHOD (getProperty, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;")
DECLARE_JNI_CLASS (SystemClass, "java/lang/System");
#undef JNI_CLASS_MEMBERS
//==============================================================================
String getSystemProperty (const String& name)
{
return juceString (LocalRef<jstring> ((jstring) getEnv()->CallStaticObjectMethod (SystemClass,
@ -177,7 +173,6 @@ namespace AndroidStatsHelpers
javaString (name).get())));
}
//==============================================================================
String getLocaleValue (bool isRegion)
{
return juceString (LocalRef<jstring> ((jstring) getEnv()->CallStaticObjectMethod (JuceAppActivity,
@ -236,16 +231,13 @@ int SystemStats::getPageSize()
//==============================================================================
String SystemStats::getLogonName()
{
const char* user = getenv ("USER");
if (const char* user = getenv ("USER"))
return CharPointer_UTF8 (user);
if (user == 0)
{
struct passwd* const pw = getpwuid (getuid());
if (pw != 0)
user = pw->pw_name;
}
if (struct passwd* const pw = getpwuid (getuid()))
return CharPointer_UTF8 (pw->pw_name);
return CharPointer_UTF8 (user);
return String::empty;
}
String SystemStats::getFullUserName()

View file

@ -165,13 +165,13 @@ File File::getSpecialLocation (const SpecialLocationType type)
{
case userHomeDirectory:
{
const char* homeDir = getenv ("HOME");
if (const char* homeDir = getenv ("HOME"))
return File (CharPointer_UTF8 (homeDir));
if (homeDir == nullptr)
if (struct passwd* const pw = getpwuid (getuid()))
homeDir = pw->pw_dir;
if (struct passwd* const pw = getpwuid (getuid()))
return File (CharPointer_UTF8 (pw->pw_dir));
return File (CharPointer_UTF8 (homeDir));
return File::nonexistent;
}
case userDocumentsDirectory: return resolveXDGFolder ("XDG_DOCUMENTS_DIR", "~");
@ -247,10 +247,9 @@ bool File::moveToTrash() const
class DirectoryIterator::NativeIterator::Pimpl
{
public:
Pimpl (const File& directory, const String& wildCard_)
Pimpl (const File& directory, const String& wc)
: parentDir (File::addTrailingSeparator (directory.getFullPathName())),
wildCard (wildCard_),
dir (opendir (directory.getFullPathName().toUTF8()))
wildCard (wc), dir (opendir (directory.getFullPathName().toUTF8()))
{
}

View file

@ -96,13 +96,13 @@ int SystemStats::getPageSize()
//==============================================================================
String SystemStats::getLogonName()
{
const char* user = getenv ("USER");
if (const char* user = getenv ("USER"))
return CharPointer_UTF8 (user);
if (user == nullptr)
if (passwd* const pw = getpwuid (getuid()))
user = pw->pw_name;
if (struct passwd* const pw = getpwuid (getuid()))
return CharPointer_UTF8 (pw->pw_name);
return CharPointer_UTF8 (user);
return String::empty;
}
String SystemStats::getFullUserName()

View file

@ -645,21 +645,6 @@ String& String::operator+= (const wchar_t* const t)
String& String::operator+= (const char* const t)
{
/* If you get an assertion here, then you're trying to create a string from 8-bit data
that contains values greater than 127. These can NOT be correctly converted to unicode
because there's no way for the String class to know what encoding was used to
create them. The source data could be UTF-8, ASCII or one of many local code-pages.
To get around this problem, you must be more explicit when you pass an ambiguous 8-bit
string to the String class - so for example if your source data is actually UTF-8,
you'd call String (CharPointer_UTF8 ("my utf8 string..")), and it would be able to
correctly convert the multi-byte characters to unicode. It's *highly* recommended that
you use UTF-8 with escape characters in your source code to represent extended characters,
because there's no other way to represent these strings in a way that isn't dependent on
the compiler, source code editor and platform.
*/
jassert (t == nullptr || CharPointer_ASCII::isValidString (t, std::numeric_limits<int>::max()));
appendCharPointer (CharPointer_UTF8 (t)); // (using UTF8 here triggers a faster code-path than ascii)
return *this;
}
@ -2093,9 +2078,30 @@ String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
StringRef::StringRef (const String::CharPointerType::CharType* stringLiteral) noexcept : text (stringLiteral)
{
jassert (stringLiteral != nullptr); // This must be a valid string literal, not a null pointer!!
#if JUCE_NATIVE_WCHAR_IS_UTF8
/* If you get an assertion here, then you're trying to create a string from 8-bit data
that contains values greater than 127. These can NOT be correctly converted to unicode
because there's no way for the String class to know what encoding was used to
create them. The source data could be UTF-8, ASCII or one of many local code-pages.
To get around this problem, you must be more explicit when you pass an ambiguous 8-bit
string to the String class - so for example if your source data is actually UTF-8,
you'd call String (CharPointer_UTF8 ("my utf8 string..")), and it would be able to
correctly convert the multi-byte characters to unicode. It's *highly* recommended that
you use UTF-8 with escape characters in your source code to represent extended characters,
because there's no other way to represent these strings in a way that isn't dependent on
the compiler, source code editor and platform.
*/
jassert (CharPointer_ASCII::isValidString (stringLiteral, std::numeric_limits<int>::max()));
#endif
}
StringRef::StringRef (String::CharPointerType stringLiteral) noexcept : text (stringLiteral)
{
jassert (stringLiteral.getAddress() != nullptr); // This must be a valid string literal, not a null pointer!!
}
StringRef::StringRef (String::CharPointerType stringLiteral) noexcept : text (stringLiteral) {}
StringRef::StringRef (const String& string) noexcept : text (string.getCharPointer()) {}
//==============================================================================