diff --git a/modules/beast_core/beast_core.h b/modules/beast_core/beast_core.h index a265ca56eb..1e0e7a0527 100644 --- a/modules/beast_core/beast_core.h +++ b/modules/beast_core/beast_core.h @@ -228,15 +228,10 @@ Some files contain portions of these external projects, licensed separately: namespace beast { -class MemoryBlock; -class File; class InputStream; class OutputStream; -class DynamicObject; class FileInputStream; class FileOutputStream; -class XmlElement; -class JSONFormatter; extern BEAST_API bool BEAST_CALLTYPE beast_isRunningUnderDebugger(); extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) noexcept; @@ -266,7 +261,6 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n # include "containers/detail/removecv.h" #include "containers/detail/copyconst.h" - #include "system/PlatformDefs.h" #include "system/TargetPlatform.h" #include "diagnostic/beast_Throw.h" @@ -279,24 +273,36 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n #include "containers/beast_LockFreeStack.h" #include "threads/beast_SpinDelay.h" #include "memory/beast_StaticObject.h" -# include "text/StringCharPointerType.h" -# include "text/StringFromNumber.h" + +#include "text/StringCharPointerType.h" +#include "text/StringFromNumber.h" #include "text/beast_String.h" +#include "time/beast_PerformedAtExit.h" +#include "diagnostic/beast_LeakChecked.h" +#include "time/beast_RelativeTime.h" +#include "time/beast_Time.h" +#include "memory/beast_HeapBlock.h" +#include "threads/beast_ScopedLock.h" +#include "threads/beast_CriticalSection.h" +#include "containers/beast_ElementComparator.h" +#include "containers/beast_ArrayAllocationBase.h" +#include "containers/beast_Array.h" +#include "misc/beast_Result.h" +#include "text/beast_StringArray.h" +#include "memory/beast_MemoryBlock.h" +#include "files/beast_File.h" +#include "time/beast_PerformanceCounter.h" + #include "memory/beast_MemoryAlignment.h" #include "memory/beast_CacheLine.h" -#include "threads/beast_CriticalSection.h" #include "threads/beast_ReadWriteMutex.h" #include "threads/beast_SharedData.h" #include "diagnostic/beast_SafeBool.h" -#include "time/beast_PerformedAtExit.h" -#include "diagnostic/beast_LeakChecked.h" #include "threads/beast_WaitableEvent.h" #include "threads/beast_Thread.h" #include "threads/beast_SpinLock.h" #include "threads/beast_ThreadLocalValue.h" #include "thread/MutexTraits.h" -#include "containers/beast_Array.h" -#include "text/beast_StringArray.h" #include "thread/TrackedMutex.h" #include "diagnostic/beast_FatalError.h" #include "diagnostic/beast_Error.h" @@ -313,14 +319,16 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n #include "functional/SharedFunction.h" #include "diagnostic/beast_ProtectedCall.h" #include "containers/beast_AbstractFifo.h" -#include "containers/beast_ArrayAllocationBase.h" -#include "containers/beast_DynamicObject.h" -#include "containers/beast_ElementComparator.h" -#include "maths/beast_Random.h" +#include "text/beast_Identifier.h" +#include "containers/beast_Variant.h" #include "containers/beast_LinkedListPointer.h" -#include "containers/beast_LockFreeQueue.h" #include "containers/beast_NamedValueSet.h" +#include "containers/beast_DynamicObject.h" +#include "maths/beast_BigInteger.h" +#include "maths/beast_Random.h" +#include "containers/beast_LockFreeQueue.h" #include "containers/beast_OwnedArray.h" +#include "text/beast_StringPairArray.h" #include "containers/beast_PropertySet.h" #include "containers/beast_SharedObjectArray.h" #include "containers/beast_ScopedValueSetter.h" @@ -329,13 +337,17 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n #include "containers/beast_SortedSet.h" #include "maths/beast_Range.h" #include "containers/beast_SparseSet.h" -#include "containers/beast_Variant.h" # include "containers/DynamicList.h" # include "containers/DynamicArray.h" #include "containers/HashMap.h" +#include "memory/beast_ScopedPointer.h" #include "files/beast_DirectoryIterator.h" -#include "files/beast_File.h" +#include "streams/beast_InputStream.h" #include "files/beast_FileInputStream.h" +#include "streams/beast_InputSource.h" +#include "streams/beast_FileInputSource.h" +#include "text/beast_NewLine.h" +#include "streams/beast_OutputStream.h" #include "files/beast_FileOutputStream.h" #include "files/beast_FileSearchPath.h" #include "files/beast_MemoryMappedFile.h" @@ -344,44 +356,33 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n #include "json/beast_JSON.h" #include "logging/beast_FileLogger.h" #include "logging/beast_Logger.h" -#include "maths/beast_BigInteger.h" #include "maths/beast_Expression.h" #include "maths/beast_Interval.h" #include "maths/beast_MathsFunctions.h" #include "maths/beast_MurmurHash.h" #include "memory/beast_ByteOrder.h" -#include "memory/beast_HeapBlock.h" #include "memory/beast_Memory.h" -#include "memory/beast_MemoryBlock.h" #include "memory/beast_OptionalScopedPointer.h" -#include "memory/beast_ScopedPointer.h" #include "memory/beast_SharedSingleton.h" #include "memory/beast_WeakReference.h" #include "memory/beast_RecycledObjectPool.h" #include "misc/beast_Main.h" -#include "misc/beast_Result.h" #include "misc/beast_Uuid.h" #include "misc/beast_WindowsRegistry.h" #include "network/beast_IPAddress.h" #include "network/beast_MACAddress.h" +#include "threads/beast_ReadWriteLock.h" #include "network/beast_NamedPipe.h" #include "network/beast_Socket.h" #include "network/beast_URL.h" #include "streams/beast_BufferedInputStream.h" -#include "streams/beast_FileInputSource.h" -#include "streams/beast_InputSource.h" -#include "streams/beast_InputStream.h" #include "streams/beast_MemoryInputStream.h" #include "streams/beast_MemoryOutputStream.h" -#include "streams/beast_OutputStream.h" #include "streams/beast_SubregionStream.h" #include "system/SystemStats.h" -#include "text/beast_Identifier.h" #include "text/beast_LocalisedStrings.h" -#include "text/beast_NewLine.h" #include "diagnostic/beast_SemanticVersion.h" -#include "text/beast_StringPairArray.h" #include "text/beast_StringPool.h" #include "text/beast_TextDiff.h" #include "threads/beast_ChildProcess.h" @@ -389,15 +390,10 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n #include "threads/beast_HighResolutionTimer.h" #include "threads/beast_InterProcessLock.h" #include "threads/beast_Process.h" -#include "threads/beast_ReadWriteLock.h" -#include "threads/beast_ScopedLock.h" #include "threads/beast_ScopedReadLock.h" #include "threads/beast_ScopedWriteLock.h" #include "threads/beast_ThreadPool.h" #include "threads/beast_TimeSliceThread.h" -#include "time/beast_PerformanceCounter.h" -#include "time/beast_RelativeTime.h" -#include "time/beast_Time.h" #include "diagnostic/beast_UnitTest.h" #include "xml/beast_XmlDocument.h" #include "xml/beast_XmlElement.h" diff --git a/modules/beast_core/containers/DynamicArray.cpp b/modules/beast_core/containers/DynamicArray.cpp index 1221e5084f..bd67b2c009 100644 --- a/modules/beast_core/containers/DynamicArray.cpp +++ b/modules/beast_core/containers/DynamicArray.cpp @@ -83,6 +83,7 @@ public: beginTestCase (s); for (std::size_t i = 0; i < numberToMutate; ++i) v.push_back (T (String::fromNumber (i))); + pass (); s = "read [] (" + String::fromNumber (numberToMutate) + ")"; beginTestCase (s); @@ -93,6 +94,7 @@ public: beginTestCase (s); for (std::size_t i = 0; i < numberToMutate; ++i) v [i].msg = "+" + String::fromNumber (i); + pass (); s = "verify [] (" + String::fromNumber (numberToMutate) + ")"; beginTestCase (s); @@ -141,6 +143,7 @@ public: step ++; iter - v.rend (); } + pass (); } { @@ -152,6 +155,7 @@ public: step ++; iter - v.crend (); } + pass (); } } diff --git a/modules/beast_core/containers/beast_Array.h b/modules/beast_core/containers/beast_Array.h index e8f79f4372..97eac103f2 100644 --- a/modules/beast_core/containers/beast_Array.h +++ b/modules/beast_core/containers/beast_Array.h @@ -24,11 +24,6 @@ #ifndef BEAST_ARRAY_H_INCLUDED #define BEAST_ARRAY_H_INCLUDED -#include "beast_ArrayAllocationBase.h" -#include "beast_ElementComparator.h" -#include "../threads/beast_CriticalSection.h" - - //============================================================================== /** Holds a resizable array of primitive or copy-by-value objects. @@ -788,7 +783,7 @@ public: @param startIndex the index of the first element to remove @param numberToRemove how many elements should be removed - @see remove, removeValue + @see remove, removeFirstMatchingValue, removeAllInstancesOf */ void removeRange (int startIndex, int numberToRemove) { @@ -816,7 +811,7 @@ public: /** Removes the last n elements from the array. @param howManyToRemove how many elements to remove from the end of the array - @see remove, removeValue, removeRange + @see remove, removeFirstMatchingValue, removeAllInstancesOf, removeRange */ void removeLast (int howManyToRemove = 1) { @@ -835,7 +830,7 @@ public: /** Removes any elements which are also in another array. @param otherArray the other array in which to look for elements to remove - @see removeValuesNotIn, remove, removeValue, removeRange + @see removeValuesNotIn, remove, removeFirstMatchingValue, removeAllInstancesOf, removeRange */ template void removeValuesIn (const OtherArrayType& otherArray) @@ -863,7 +858,7 @@ public: Only elements which occur in this other array will be retained. @param otherArray the array in which to look for elements NOT to remove - @see removeValuesIn, remove, removeValue, removeRange + @see removeValuesIn, remove, removeFirstMatchingValue, removeAllInstancesOf, removeRange */ template void removeValuesNotIn (const OtherArrayType& otherArray) diff --git a/modules/beast_core/containers/beast_ArrayAllocationBase.h b/modules/beast_core/containers/beast_ArrayAllocationBase.h index a0cdc1cfe0..6887392cd6 100644 --- a/modules/beast_core/containers/beast_ArrayAllocationBase.h +++ b/modules/beast_core/containers/beast_ArrayAllocationBase.h @@ -24,9 +24,6 @@ #ifndef BEAST_ARRAYALLOCATIONBASE_H_INCLUDED #define BEAST_ARRAYALLOCATIONBASE_H_INCLUDED -#include "../memory/beast_HeapBlock.h" - - //============================================================================== /** Implements some basic array storage allocation functions. diff --git a/modules/beast_core/containers/beast_DynamicObject.h b/modules/beast_core/containers/beast_DynamicObject.h index bd6e9f0493..56e4cf7b65 100644 --- a/modules/beast_core/containers/beast_DynamicObject.h +++ b/modules/beast_core/containers/beast_DynamicObject.h @@ -24,9 +24,6 @@ #ifndef BEAST_DYNAMICOBJECT_H_INCLUDED #define BEAST_DYNAMICOBJECT_H_INCLUDED -#include "beast_NamedValueSet.h" - - //============================================================================== /** Represents a dynamically implemented object. diff --git a/modules/beast_core/containers/beast_ElementComparator.h b/modules/beast_core/containers/beast_ElementComparator.h index ca63eaf6b8..438628ed9e 100644 --- a/modules/beast_core/containers/beast_ElementComparator.h +++ b/modules/beast_core/containers/beast_ElementComparator.h @@ -24,6 +24,26 @@ #ifndef BEAST_ELEMENTCOMPARATOR_H_INCLUDED #define BEAST_ELEMENTCOMPARATOR_H_INCLUDED +#ifndef DOXYGEN + +/** This is an internal helper class which converts a beast ElementComparator style + class (using a "compareElements" method) into a class that's compatible with + std::sort (i.e. using an operator() to compare the elements) +*/ +template +struct SortFunctionConverter +{ + SortFunctionConverter (ElementComparator& e) : comparator (e) {} + + template + bool operator() (Type a, Type b) { return comparator.compareElements (a, b) < 0; } + +private: + ElementComparator& comparator; + SortFunctionConverter& operator= (const SortFunctionConverter&); +}; + +#endif //============================================================================== /** @@ -60,117 +80,12 @@ static void sortArray (ElementComparator& comparator, int lastElement, const bool retainOrderOfEquivalentItems) { - (void) comparator; // if you pass in an object with a static compareElements() method, this - // avoids getting warning messages about the parameter being unused + SortFunctionConverter converter (comparator); - if (lastElement > firstElement) - { - if (retainOrderOfEquivalentItems) - { - for (int i = firstElement; i < lastElement; ++i) - { - if (comparator.compareElements (array[i], array [i + 1]) > 0) - { - std::swap (array[i], array[i + 1]); - - if (i > firstElement) - i -= 2; - } - } - } - else - { - int fromStack[30], toStack[30]; - int stackIndex = 0; - - for (;;) - { - const int size = (lastElement - firstElement) + 1; - - if (size <= 8) - { - int j = lastElement; - int maxIndex; - - while (j > firstElement) - { - maxIndex = firstElement; - for (int k = firstElement + 1; k <= j; ++k) - if (comparator.compareElements (array[k], array [maxIndex]) > 0) - maxIndex = k; - - std::swap (array[j], array[maxIndex]); - --j; - } - } - else - { - const int mid = firstElement + (size >> 1); - std::swap (array[mid], array[firstElement]); - - int i = firstElement; - int j = lastElement + 1; - - for (;;) - { - while (++i <= lastElement - && comparator.compareElements (array[i], array [firstElement]) <= 0) - {} - - while (--j > firstElement - && comparator.compareElements (array[j], array [firstElement]) >= 0) - {} - - if (j < i) - break; - - std::swap (array[i], array[j]); - } - - std::swap (array[j], array[firstElement]); - - if (j - 1 - firstElement >= lastElement - i) - { - if (firstElement + 1 < j) - { - fromStack [stackIndex] = firstElement; - toStack [stackIndex] = j - 1; - ++stackIndex; - } - - if (i < lastElement) - { - firstElement = i; - continue; - } - } - else - { - if (i < lastElement) - { - fromStack [stackIndex] = i; - toStack [stackIndex] = lastElement; - ++stackIndex; - } - - if (firstElement + 1 < j) - { - lastElement = j - 1; - continue; - } - } - } - - if (--stackIndex < 0) - break; - - bassert (stackIndex < numElementsInArray (fromStack)); - - firstElement = fromStack [stackIndex]; - lastElement = toStack [stackIndex]; - } - } - } + if (retainOrderOfEquivalentItems) + std::stable_sort (array + firstElement, array + lastElement + 1, converter); + else + std::sort (array + firstElement, array + lastElement + 1, converter); } @@ -270,5 +185,5 @@ public: } }; +#endif -#endif // BEAST_ELEMENTCOMPARATOR_H_INCLUDED diff --git a/modules/beast_core/containers/beast_NamedValueSet.h b/modules/beast_core/containers/beast_NamedValueSet.h index 486e44c986..24e4bcc65e 100644 --- a/modules/beast_core/containers/beast_NamedValueSet.h +++ b/modules/beast_core/containers/beast_NamedValueSet.h @@ -24,8 +24,6 @@ #ifndef BEAST_NAMEDVALUESET_H_INCLUDED #define BEAST_NAMEDVALUESET_H_INCLUDED -#include "beast_Variant.h" -#include "../containers/beast_LinkedListPointer.h" class XmlElement; #ifndef DOXYGEN class JSONFormatter; diff --git a/modules/beast_core/containers/beast_PropertySet.h b/modules/beast_core/containers/beast_PropertySet.h index c0c5877386..40d84f992d 100644 --- a/modules/beast_core/containers/beast_PropertySet.h +++ b/modules/beast_core/containers/beast_PropertySet.h @@ -24,11 +24,6 @@ #ifndef BEAST_PROPERTYSET_H_INCLUDED #define BEAST_PROPERTYSET_H_INCLUDED -#include "../text/beast_StringPairArray.h" -#include "../xml/beast_XmlElement.h" -#include "../containers/beast_Variant.h" - - //============================================================================== /** A set of named property values, which can be strings, integers, floating point, etc. diff --git a/modules/beast_core/containers/beast_SharedObjectArray.h b/modules/beast_core/containers/beast_SharedObjectArray.h index 5224a4f73b..d2205c17d4 100644 --- a/modules/beast_core/containers/beast_SharedObjectArray.h +++ b/modules/beast_core/containers/beast_SharedObjectArray.h @@ -24,11 +24,6 @@ #ifndef BEAST_SHAREDOBJECTARRAY_H_INCLUDED #define BEAST_SHAREDOBJECTARRAY_H_INCLUDED -#include "beast_ArrayAllocationBase.h" -#include "beast_ElementComparator.h" -#include "../threads/beast_CriticalSection.h" - - //============================================================================== /** Holds a list of objects derived from SharedObject. diff --git a/modules/beast_core/containers/beast_SortedSet.h b/modules/beast_core/containers/beast_SortedSet.h index c2d21d2d30..d5a96a839c 100644 --- a/modules/beast_core/containers/beast_SortedSet.h +++ b/modules/beast_core/containers/beast_SortedSet.h @@ -24,15 +24,11 @@ #ifndef BEAST_SORTEDSET_H_INCLUDED #define BEAST_SORTEDSET_H_INCLUDED -#include "beast_ArrayAllocationBase.h" -#include "../threads/beast_CriticalSection.h" - #if BEAST_MSVC #pragma warning (push) #pragma warning (disable: 4512) #endif - //============================================================================== /** Holds a set of unique primitive objects, such as ints or doubles. @@ -492,4 +488,5 @@ private: #pragma warning (pop) #endif -#endif // BEAST_SORTEDSET_H_INCLUDED +#endif + diff --git a/modules/beast_core/containers/beast_Variant.h b/modules/beast_core/containers/beast_Variant.h index c6b5adf299..927979080e 100644 --- a/modules/beast_core/containers/beast_Variant.h +++ b/modules/beast_core/containers/beast_Variant.h @@ -24,11 +24,6 @@ #ifndef BEAST_VARIANT_H_INCLUDED #define BEAST_VARIANT_H_INCLUDED -#include "../text/beast_Identifier.h" -#include "../streams/beast_OutputStream.h" -#include "../streams/beast_InputStream.h" -#include "../containers/beast_Array.h" - #ifndef DOXYGEN class SharedObject; class DynamicObject; diff --git a/modules/beast_core/files/beast_DirectoryIterator.h b/modules/beast_core/files/beast_DirectoryIterator.h index a1bdb42500..74d6153283 100644 --- a/modules/beast_core/files/beast_DirectoryIterator.h +++ b/modules/beast_core/files/beast_DirectoryIterator.h @@ -24,10 +24,6 @@ #ifndef BEAST_DIRECTORYITERATOR_H_INCLUDED #define BEAST_DIRECTORYITERATOR_H_INCLUDED -#include "beast_File.h" -#include "../memory/beast_ScopedPointer.h" - - //============================================================================== /** Searches through a the files in a directory, returning each file that is found. diff --git a/modules/beast_core/files/beast_File.cpp b/modules/beast_core/files/beast_File.cpp index c980ff7aa0..319f4ab965 100644 --- a/modules/beast_core/files/beast_File.cpp +++ b/modules/beast_core/files/beast_File.cpp @@ -57,10 +57,6 @@ File::File (const File& other) { } -File::~File() noexcept -{ -} - File File::createFileWithoutCheckingPath (const String& path) noexcept { File f; diff --git a/modules/beast_core/files/beast_File.h b/modules/beast_core/files/beast_File.h index cfd724f023..e5cfa4fe36 100644 --- a/modules/beast_core/files/beast_File.h +++ b/modules/beast_core/files/beast_File.h @@ -24,16 +24,6 @@ #ifndef BEAST_FILE_H_INCLUDED #define BEAST_FILE_H_INCLUDED -#include "../containers/beast_Array.h" -#include "../time/beast_Time.h" -#include "../text/beast_StringArray.h" -#include "../memory/beast_MemoryBlock.h" -#include "../memory/beast_ScopedPointer.h" -#include "../misc/beast_Result.h" -class FileInputStream; -class FileOutputStream; - - //============================================================================== /** Represents a local file or directory. @@ -46,14 +36,14 @@ class FileOutputStream; @see FileInputStream, FileOutputStream */ -class BEAST_API File : LeakChecked +class BEAST_API File { public: //============================================================================== /** Creates an (invalid) file object. The file is initially set to an empty path, so getFullPath() will return - an empty string, and comparing the file to File::nonexistent() will return + an empty string, and comparing the file to File::nonexistent will return true. You can use its operator= method to point it at a proper file. @@ -70,13 +60,13 @@ public: On the Mac/Linux, the path can include "~" notation for referring to user home directories. */ - File (const String& path); + File (const String& absolutePath); /** Creates a copy of another file object. */ - File (const File& other); + File (const File&); /** Destructor. */ - ~File() noexcept; + ~File() noexcept {} /** Sets the file based on an absolute pathname. @@ -88,14 +78,14 @@ public: On the Mac/Linux, the path can include "~" notation for referring to user home directories. */ - File& operator= (const String& newFilePath); + File& operator= (const String& newAbsolutePath); /** Copies from another file object. */ File& operator= (const File& otherFile); #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS - File (File&& otherFile) noexcept; - File& operator= (File&& otherFile) noexcept; + File (File&&) noexcept; + File& operator= (File&&) noexcept; #endif //============================================================================== @@ -200,8 +190,7 @@ public: @param extensionToTest the extension to look for - it doesn't matter whether or not this string has a dot at the start, so ".wav" and "wav" - will have the same effect. The comparison used is - case-insensitve. To compare with multiple extensions, this + will have the same effect. To compare with multiple extensions, this parameter can contain multiple strings, separated by semi-colons - so, for example: hasFileExtension (".jpeg;png;gif") would return true if the file has any of those three extensions. @@ -256,7 +245,7 @@ public: File ("/moose/fish").getChildFile ("../foo.txt") will produce "/moose/foo.txt". If the string is actually an absolute path, it will be treated as such, e.g. - File ("/moose/fish").getChildFile ("/foo.txt") will produce "/foo.txt" + File ("/moose/fish").getChildFile ("/foo.txt") will produce "/foo.txt" @see getSiblingFile, getParentDirectory, getRelativePathFrom, isAChildOf */ @@ -323,13 +312,13 @@ public: //============================================================================== /** Compares the pathnames for two files. */ - bool operator== (const File& otherFile) const; + bool operator== (const File&) const; /** Compares the pathnames for two files. */ - bool operator!= (const File& otherFile) const; + bool operator!= (const File&) const; /** Compares the pathnames for two files. */ - bool operator< (const File& otherFile) const; + bool operator< (const File&) const; /** Compares the pathnames for two files. */ - bool operator> (const File& otherFile) const; + bool operator> (const File&) const; //============================================================================== /** Checks whether a file can be created or written to. @@ -767,6 +756,15 @@ public: /** The folder that contains the user's desktop objects. */ userDesktopDirectory, + /** The most likely place where a user might store their music files. */ + userMusicDirectory, + + /** The most likely place where a user might store their movie files. */ + userMoviesDirectory, + + /** The most likely place where a user might store their picture files. */ + userPicturesDirectory, + /** The folder in which applications store their persistent user-specific settings. On Windows, this might be "\Documents and Settings\username\Application Data". On the Mac, it might be "~/Library". If you're going to store your settings in here, @@ -784,6 +782,13 @@ public: */ commonApplicationDataDirectory, + /** A place to put documents which are shared by all users of the machine. + On Windows this may be somewhere like "C:\Users\Public\Documents", on OSX it + will be something like "/Users/Shared". Other OSes may have no such concept + though, so be careful. + */ + commonDocumentsDirectory, + /** The folder that should be used for temporary files. Always delete them when you're finished, to keep the user's computer tidy! */ @@ -826,16 +831,7 @@ public: So on windows, this would be something like "c:\program files", on the Mac "/Applications", or "/usr" on linux. */ - globalApplicationsDirectory, - - /** The most likely place where a user might store their music files. */ - userMusicDirectory, - - /** The most likely place where a user might store their movie files. */ - userMoviesDirectory, - - /** The most likely place where a user might store their picture files. */ - userPicturesDirectory + globalApplicationsDirectory }; /** Finds the location of a special type of file or directory, such as a home folder or @@ -880,19 +876,20 @@ public: static const String separatorString; //============================================================================== - /** Removes illegal characters from a filename. + /** Returns a version of a filename with any illegal characters removed. This will return a copy of the given string after removing characters that are not allowed in a legal filename, and possibly shortening the string if it's too long. - Because this will remove slashes, don't use it on an absolute pathname. + Because this will remove slashes, don't use it on an absolute pathname - use + createLegalPathName() for that. @see createLegalPathName */ static String createLegalFileName (const String& fileNameToFix); - /** Removes illegal characters from a pathname. + /** Returns a version of a path with any illegal characters removed. Similar to createLegalFileName(), but this won't remove slashes, so can be used on a complete pathname. @@ -912,7 +909,7 @@ public: Best to avoid this unless you really know what you're doing. */ - static File createFileWithoutCheckingPath (const String& path) noexcept; + static File createFileWithoutCheckingPath (const String& absolutePath) noexcept; /** Adds a separator character to the end of a path if it doesn't already have one. */ static String addTrailingSeparator (const String& path); @@ -951,4 +948,5 @@ private: bool setFileReadOnlyInternal (bool) const; }; -#endif // BEAST_FILE_H_INCLUDED +#endif + diff --git a/modules/beast_core/files/beast_FileInputStream.h b/modules/beast_core/files/beast_FileInputStream.h index 883e74b909..cbf1b47bf5 100644 --- a/modules/beast_core/files/beast_FileInputStream.h +++ b/modules/beast_core/files/beast_FileInputStream.h @@ -24,10 +24,6 @@ #ifndef BEAST_FILEINPUTSTREAM_H_INCLUDED #define BEAST_FILEINPUTSTREAM_H_INCLUDED -#include "beast_File.h" -#include "../streams/beast_InputStream.h" - - //============================================================================== /** An input stream that reads from a local file. diff --git a/modules/beast_core/files/beast_FileOutputStream.h b/modules/beast_core/files/beast_FileOutputStream.h index 26c05c1486..74b30d825b 100644 --- a/modules/beast_core/files/beast_FileOutputStream.h +++ b/modules/beast_core/files/beast_FileOutputStream.h @@ -24,9 +24,6 @@ #ifndef BEAST_FILEOUTPUTSTREAM_H_INCLUDED #define BEAST_FILEOUTPUTSTREAM_H_INCLUDED -#include "beast_File.h" -#include "../streams/beast_OutputStream.h" - //============================================================================== /** An output stream that writes into a local file. diff --git a/modules/beast_core/files/beast_FileSearchPath.h b/modules/beast_core/files/beast_FileSearchPath.h index 9c88f4729d..7c7d075e45 100644 --- a/modules/beast_core/files/beast_FileSearchPath.h +++ b/modules/beast_core/files/beast_FileSearchPath.h @@ -24,10 +24,6 @@ #ifndef BEAST_FILESEARCHPATH_H_INCLUDED #define BEAST_FILESEARCHPATH_H_INCLUDED -#include "beast_File.h" -#include "../text/beast_StringArray.h" - - //============================================================================== /** Encapsulates a set of folders that make up a search path. diff --git a/modules/beast_core/files/beast_MemoryMappedFile.h b/modules/beast_core/files/beast_MemoryMappedFile.h index 5c5659a0c0..f621966519 100644 --- a/modules/beast_core/files/beast_MemoryMappedFile.h +++ b/modules/beast_core/files/beast_MemoryMappedFile.h @@ -24,7 +24,6 @@ #ifndef BEAST_MEMORYMAPPEDFILE_H_INCLUDED #define BEAST_MEMORYMAPPEDFILE_H_INCLUDED -#include "beast_File.h" //============================================================================== /** diff --git a/modules/beast_core/files/beast_RandomAccessFile.h b/modules/beast_core/files/beast_RandomAccessFile.h index e17d6caced..05f87a3116 100644 --- a/modules/beast_core/files/beast_RandomAccessFile.h +++ b/modules/beast_core/files/beast_RandomAccessFile.h @@ -20,8 +20,6 @@ #ifndef BEAST_RANDOMACCESSFILE_H_INCLUDED #define BEAST_RANDOMACCESSFILE_H_INCLUDED -#include "../misc/beast_Result.h" - /** Provides random access reading and writing to an operating system file. This class wraps the underlying native operating system routines for diff --git a/modules/beast_core/files/beast_TemporaryFile.h b/modules/beast_core/files/beast_TemporaryFile.h index 52354c7fa2..9bea480aa1 100644 --- a/modules/beast_core/files/beast_TemporaryFile.h +++ b/modules/beast_core/files/beast_TemporaryFile.h @@ -24,9 +24,6 @@ #ifndef BEAST_TEMPORARYFILE_H_INCLUDED #define BEAST_TEMPORARYFILE_H_INCLUDED -#include "beast_File.h" - - //============================================================================== /** Manages a temporary file, which will be deleted when this object is deleted. diff --git a/modules/beast_core/json/beast_JSON.cpp b/modules/beast_core/json/beast_JSON.cpp index d80df86fcf..ebd6051a94 100644 --- a/modules/beast_core/json/beast_JSON.cpp +++ b/modules/beast_core/json/beast_JSON.cpp @@ -311,7 +311,7 @@ private: buffer.appendUTF8Char (c); } - result = buffer.toString(); + result = buffer.toUTF8 (); return Result::ok(); } }; @@ -521,7 +521,7 @@ String JSON::toString (const var& data, const bool allOnOneLine) { MemoryOutputStream mo (1024); JSONFormatter::write (mo, data, 0, allOnOneLine); - return mo.toString(); + return mo.toUTF8 (); } void JSON::writeToStream (OutputStream& output, const var& data, const bool allOnOneLine) diff --git a/modules/beast_core/json/beast_JSON.h b/modules/beast_core/json/beast_JSON.h index ab2c74efd7..6e854f63fc 100644 --- a/modules/beast_core/json/beast_JSON.h +++ b/modules/beast_core/json/beast_JSON.h @@ -24,13 +24,10 @@ #ifndef BEAST_JSON_H_INCLUDED #define BEAST_JSON_H_INCLUDED -#include "../misc/beast_Result.h" -#include "../containers/beast_Variant.h" class InputStream; class OutputStream; class File; - //============================================================================== /** Contains static methods for converting JSON-formatted text to and from var objects. diff --git a/modules/beast_core/logging/beast_FileLogger.h b/modules/beast_core/logging/beast_FileLogger.h index 396d78c747..ddf887ee76 100644 --- a/modules/beast_core/logging/beast_FileLogger.h +++ b/modules/beast_core/logging/beast_FileLogger.h @@ -24,11 +24,6 @@ #ifndef BEAST_FILELOGGER_H_INCLUDED #define BEAST_FILELOGGER_H_INCLUDED -#include "beast_Logger.h" -#include "../files/beast_File.h" -#include "../memory/beast_ScopedPointer.h" - - //============================================================================== /** A simple implementation of a Logger that writes to a file. diff --git a/modules/beast_core/logging/beast_Logger.h b/modules/beast_core/logging/beast_Logger.h index a00ce2c4cd..f7336c4e0b 100644 --- a/modules/beast_core/logging/beast_Logger.h +++ b/modules/beast_core/logging/beast_Logger.h @@ -24,9 +24,6 @@ #ifndef BEAST_LOGGER_H_INCLUDED #define BEAST_LOGGER_H_INCLUDED -#include "../text/beast_String.h" - - //============================================================================== /** Acts as an application-wide logging class. diff --git a/modules/beast_core/maths/beast_BigInteger.cpp b/modules/beast_core/maths/beast_BigInteger.cpp index 6da6863b91..f358981ec1 100644 --- a/modules/beast_core/maths/beast_BigInteger.cpp +++ b/modules/beast_core/maths/beast_BigInteger.cpp @@ -951,7 +951,9 @@ String BigInteger::toString (const int base, const int minimumNumCharacters) con void BigInteger::parseString (const String& text, const int base) { clear(); - String::CharPointerType t (text.getCharPointer()); + String::CharPointerType t (text.getCharPointer().findEndOfWhitespace ()); + + setNegative (*t == (beast_wchar) '-'); if (base == 2 || base == 8 || base == 16) { @@ -992,8 +994,6 @@ void BigInteger::parseString (const String& text, const int base) } } } - - setNegative (text.trimStart().startsWithChar ('-')); } MemoryBlock BigInteger::toMemoryBlock() const diff --git a/modules/beast_core/maths/beast_BigInteger.h b/modules/beast_core/maths/beast_BigInteger.h index cd886a29f4..0d2c2ea7fb 100644 --- a/modules/beast_core/maths/beast_BigInteger.h +++ b/modules/beast_core/maths/beast_BigInteger.h @@ -24,11 +24,6 @@ #ifndef BEAST_BIGINTEGER_H_INCLUDED #define BEAST_BIGINTEGER_H_INCLUDED -#include "../text/beast_String.h" -#include "../memory/beast_HeapBlock.h" -class MemoryBlock; - - //============================================================================== /** An arbitrarily large integer class. diff --git a/modules/beast_core/maths/beast_Expression.h b/modules/beast_core/maths/beast_Expression.h index 8c217a6c62..d72a499c09 100644 --- a/modules/beast_core/maths/beast_Expression.h +++ b/modules/beast_core/maths/beast_Expression.h @@ -24,10 +24,6 @@ #ifndef BEAST_EXPRESSION_H_INCLUDED #define BEAST_EXPRESSION_H_INCLUDED -#include "../containers/beast_Array.h" -#include "../memory/beast_ScopedPointer.h" - - //============================================================================== /** A class for dynamically evaluating simple numeric expressions. diff --git a/modules/beast_core/maths/beast_Random.h b/modules/beast_core/maths/beast_Random.h index bcce19d161..ff6df7e58b 100644 --- a/modules/beast_core/maths/beast_Random.h +++ b/modules/beast_core/maths/beast_Random.h @@ -24,9 +24,6 @@ #ifndef BEAST_RANDOM_H_INCLUDED #define BEAST_RANDOM_H_INCLUDED -#include "beast_BigInteger.h" - - //============================================================================== /** A random number generator. diff --git a/modules/beast_core/memory/beast_MemoryBlock.cpp b/modules/beast_core/memory/beast_MemoryBlock.cpp index c4c016ba18..1d57ece749 100644 --- a/modules/beast_core/memory/beast_MemoryBlock.cpp +++ b/modules/beast_core/memory/beast_MemoryBlock.cpp @@ -347,7 +347,8 @@ void MemoryBlock::loadFromHexString (const String& hex) } //============================================================================== -const char* const MemoryBlock::encodingTable = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; + +static char const* const base64EncodingTable = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; String MemoryBlock::toBase64Encoding() const { @@ -362,7 +363,7 @@ String MemoryBlock::toBase64Encoding() const d.write ('.'); for (size_t i = 0; i < numChars; ++i) - d.write ((beast_wchar) (uint8) encodingTable [getBitRange (i * 6, 6)]); + d.write ((beast_wchar) (uint8) base64EncodingTable [getBitRange (i * 6, 6)]); d.writeNull(); return destString; @@ -391,7 +392,7 @@ bool MemoryBlock::fromBase64Encoding (const String& s) for (int j = 0; j < 64; ++j) { - if (encodingTable[j] == c) + if (base64EncodingTable[j] == c) { setBitRange ((size_t) pos, 6, j); pos += 6; diff --git a/modules/beast_core/memory/beast_MemoryBlock.h b/modules/beast_core/memory/beast_MemoryBlock.h index 44ed81932c..b5d9cf0f2d 100644 --- a/modules/beast_core/memory/beast_MemoryBlock.h +++ b/modules/beast_core/memory/beast_MemoryBlock.h @@ -24,10 +24,6 @@ #ifndef BEAST_MEMORYBLOCK_H_INCLUDED #define BEAST_MEMORYBLOCK_H_INCLUDED -#include "../text/beast_String.h" -#include "../memory/beast_HeapBlock.h" - - //============================================================================== /** A class to hold a resizable block of raw data. @@ -266,8 +262,7 @@ private: //============================================================================== HeapBlock data; size_t size; - static const char* const encodingTable; }; +#endif -#endif // BEAST_MEMORYBLOCK_H_INCLUDED diff --git a/modules/beast_core/memory/beast_OptionalScopedPointer.h b/modules/beast_core/memory/beast_OptionalScopedPointer.h index f005403fdd..9aeffd7a1f 100644 --- a/modules/beast_core/memory/beast_OptionalScopedPointer.h +++ b/modules/beast_core/memory/beast_OptionalScopedPointer.h @@ -24,9 +24,6 @@ #ifndef BEAST_OPTIONALSCOPEDPOINTER_H_INCLUDED #define BEAST_OPTIONALSCOPEDPOINTER_H_INCLUDED -#include "beast_ScopedPointer.h" - - //============================================================================== /** Holds a pointer to an object which can optionally be deleted when this pointer diff --git a/modules/beast_core/misc/beast_Result.h b/modules/beast_core/misc/beast_Result.h index 901e99451f..d596a8d6a5 100644 --- a/modules/beast_core/misc/beast_Result.h +++ b/modules/beast_core/misc/beast_Result.h @@ -24,8 +24,6 @@ #ifndef BEAST_RESULT_H_INCLUDED #define BEAST_RESULT_H_INCLUDED -#include "../text/beast_String.h" - /** Represents the 'success' or 'failure' of an operation, and holds an associated error message to describe the error when there's a failure. diff --git a/modules/beast_core/misc/beast_Uuid.h b/modules/beast_core/misc/beast_Uuid.h index 4590729071..36b08c43e4 100644 --- a/modules/beast_core/misc/beast_Uuid.h +++ b/modules/beast_core/misc/beast_Uuid.h @@ -24,9 +24,6 @@ #ifndef BEAST_UUID_H_INCLUDED #define BEAST_UUID_H_INCLUDED -#include "../text/beast_String.h" - - //============================================================================== /** A universally unique 128-bit identifier. diff --git a/modules/beast_core/native/beast_android_Files.cpp b/modules/beast_core/native/beast_android_Files.cpp index d5ca3facd0..a789f7e8d3 100644 --- a/modules/beast_core/native/beast_android_Files.cpp +++ b/modules/beast_core/native/beast_android_Files.cpp @@ -103,6 +103,7 @@ File File::getSpecialLocation (const SpecialLocationType type) case userMoviesDirectory: case userPicturesDirectory: case userApplicationDataDirectory: + case commonDocumentsDirectory: case userDesktopDirectory: return File (android.appDataDir); @@ -113,7 +114,6 @@ File File::getSpecialLocation (const SpecialLocationType type) return File ("/system/app"); case tempDirectory: - //return File (AndroidStatsHelpers::getSystemProperty ("java.io.tmpdir")); return File (android.appDataDir).getChildFile (".temp"); case invokedExecutableFile: diff --git a/modules/beast_core/native/beast_linux_Files.cpp b/modules/beast_core/native/beast_linux_Files.cpp index d1253b92fb..e2370c91e3 100644 --- a/modules/beast_core/native/beast_linux_Files.cpp +++ b/modules/beast_core/native/beast_linux_Files.cpp @@ -162,13 +162,12 @@ File File::getSpecialLocation (const SpecialLocationType type) { const char* homeDir = getenv ("HOME"); - if (homeDir == nullptr) - { - struct passwd* const pw = getpwuid (getuid()); - if (pw != nullptr) - homeDir = pw->pw_dir; - } + if (const char* homeDir = getenv ("HOME")) + return File (CharPointer_UTF8 (homeDir)); + if (struct passwd* const pw = getpwuid (getuid())) + return File (CharPointer_UTF8 (pw->pw_dir)); + return File (CharPointer_UTF8 (homeDir)); } @@ -178,6 +177,7 @@ File File::getSpecialLocation (const SpecialLocationType type) case userPicturesDirectory: return resolveXDGFolder ("XDG_PICTURES_DIR", "~"); case userDesktopDirectory: return resolveXDGFolder ("XDG_DESKTOP_DIR", "~/Desktop"); case userApplicationDataDirectory: return File ("~"); + case commonDocumentsDirectory: case commonApplicationDataDirectory: return File ("/var"); case globalApplicationsDirectory: return File ("/usr"); diff --git a/modules/beast_core/native/beast_mac_Files.mm b/modules/beast_core/native/beast_mac_Files.mm index 49115f75e4..03e8fe7c39 100644 --- a/modules/beast_core/native/beast_mac_Files.mm +++ b/modules/beast_core/native/beast_mac_Files.mm @@ -208,6 +208,7 @@ File File::getSpecialLocation (const SpecialLocationType type) case userPicturesDirectory: resultPath = "~/Pictures"; break; case userApplicationDataDirectory: resultPath = "~/Library"; break; case commonApplicationDataDirectory: resultPath = "/Library"; break; + case commonDocumentsDirectory: resultPath = "/Users/Shared"; break; case globalApplicationsDirectory: resultPath = "/Applications"; break; case invokedExecutableFile: diff --git a/modules/beast_core/native/beast_posix_SharedCode.h b/modules/beast_core/native/beast_posix_SharedCode.h index 93126fa0a7..6b9cb1672f 100644 --- a/modules/beast_core/native/beast_posix_SharedCode.h +++ b/modules/beast_core/native/beast_posix_SharedCode.h @@ -29,29 +29,14 @@ CriticalSection::CriticalSection() noexcept #if ! BEAST_ANDROID pthread_mutexattr_setprotocol (&atts, PTHREAD_PRIO_INHERIT); #endif - pthread_mutex_init (&internal, &atts); -} - -CriticalSection::~CriticalSection() noexcept -{ - pthread_mutex_destroy (&internal); -} - -void CriticalSection::enter() const noexcept -{ - pthread_mutex_lock (&internal); -} - -bool CriticalSection::tryEnter() const noexcept -{ - return pthread_mutex_trylock (&internal) == 0; -} - -void CriticalSection::exit() const noexcept -{ - pthread_mutex_unlock (&internal); + pthread_mutex_init (&mutex, &atts); + pthread_mutexattr_destroy (&atts); } +CriticalSection::~CriticalSection() noexcept { pthread_mutex_destroy (&mutex); } +void CriticalSection::enter() const noexcept { pthread_mutex_lock (&mutex); } +bool CriticalSection::tryEnter() const noexcept { return pthread_mutex_trylock (&mutex) == 0; } +void CriticalSection::exit() const noexcept { pthread_mutex_unlock (&mutex); } //============================================================================== WaitableEvent::WaitableEvent (const bool useManualReset, bool initiallySignaled) noexcept diff --git a/modules/beast_core/native/beast_win32_Files.cpp b/modules/beast_core/native/beast_win32_Files.cpp index 5acb1fae0f..e3952b82a1 100644 --- a/modules/beast_core/native/beast_win32_Files.cpp +++ b/modules/beast_core/native/beast_win32_Files.cpp @@ -670,6 +670,7 @@ File BEAST_CALLTYPE File::getSpecialLocation (const SpecialLocationType type) case userDesktopDirectory: csidlType = CSIDL_DESKTOP; break; case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break; case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break; + case commonDocumentsDirectory: csidlType = CSIDL_COMMON_DOCUMENTS; break; case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break; case userMusicDirectory: csidlType = 0x0d; /*CSIDL_MYMUSIC*/ break; case userMoviesDirectory: csidlType = 0x0e; /*CSIDL_MYVIDEO*/ break; diff --git a/modules/beast_core/native/beast_win32_Threads.cpp b/modules/beast_core/native/beast_win32_Threads.cpp index b089401166..a8d0e18fca 100644 --- a/modules/beast_core/native/beast_win32_Threads.cpp +++ b/modules/beast_core/native/beast_win32_Threads.cpp @@ -23,6 +23,13 @@ HWND beast_messageWindowHandle = 0; // (this is used by other parts of the codebase) +void* getUser32Function (const char* functionName) +{ + HMODULE module = GetModuleHandleA ("user32.dll"); + bassert (module != 0); + return (void*) GetProcAddress (module, functionName); +} + //============================================================================== #if ! BEAST_USE_INTRINSICS // In newer compilers, the inline versions of these are used (in beast_Atomic.h), but in @@ -47,64 +54,37 @@ __int64 beast_InterlockedCompareExchange64 (volatile __int64* value, __int64 new #endif //============================================================================== + CriticalSection::CriticalSection() noexcept { // (just to check the MS haven't changed this structure and broken things...) - #if BEAST_VC7_OR_EARLIER + #if BEAST_VC7_OR_EARLIER static_bassert (sizeof (CRITICAL_SECTION) <= 24); - #else - static_bassert (sizeof (CRITICAL_SECTION) <= sizeof (internal)); - #endif + #else + static_bassert (sizeof (CRITICAL_SECTION) <= sizeof (section)); + #endif - InitializeCriticalSection ((CRITICAL_SECTION*) internal); + InitializeCriticalSection ((CRITICAL_SECTION*) section); } -CriticalSection::~CriticalSection() noexcept -{ - DeleteCriticalSection ((CRITICAL_SECTION*) internal); -} - -void CriticalSection::enter() const noexcept -{ - EnterCriticalSection ((CRITICAL_SECTION*) internal); -} - -bool CriticalSection::tryEnter() const noexcept -{ - return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE; -} - -void CriticalSection::exit() const noexcept -{ - LeaveCriticalSection ((CRITICAL_SECTION*) internal); -} +CriticalSection::~CriticalSection() noexcept { DeleteCriticalSection ((CRITICAL_SECTION*) section); } +void CriticalSection::enter() const noexcept { EnterCriticalSection ((CRITICAL_SECTION*) section); } +bool CriticalSection::tryEnter() const noexcept { return TryEnterCriticalSection ((CRITICAL_SECTION*) section) != FALSE; } +void CriticalSection::exit() const noexcept { LeaveCriticalSection ((CRITICAL_SECTION*) section); } //============================================================================== + WaitableEvent::WaitableEvent (const bool manualReset, bool initiallySignaled) noexcept - : internal (CreateEvent (0, manualReset ? TRUE : FALSE, FALSE, 0)) -{ - if (initiallySignaled) - signal (); -} + : handle (CreateEvent (0, manualReset ? TRUE : FALSE, initiallySignaled ? TRUE : FALSE, 0)) {} -WaitableEvent::~WaitableEvent() noexcept -{ - CloseHandle (internal); -} +WaitableEvent::~WaitableEvent() noexcept { CloseHandle (handle); } -bool WaitableEvent::wait (const int timeOutMillisecs) const noexcept -{ - return WaitForSingleObject (internal, (DWORD) timeOutMillisecs) == WAIT_OBJECT_0; -} +void WaitableEvent::signal() const noexcept { SetEvent (handle); } +void WaitableEvent::reset() const noexcept { ResetEvent (handle); } -void WaitableEvent::signal() const noexcept +bool WaitableEvent::wait (const int timeOutMs) const noexcept { - SetEvent (internal); -} - -void WaitableEvent::reset() const noexcept -{ - ResetEvent (internal); + return WaitForSingleObject (handle, (DWORD) timeOutMs) == WAIT_OBJECT_0; } //============================================================================== diff --git a/modules/beast_core/network/beast_MACAddress.h b/modules/beast_core/network/beast_MACAddress.h index 175f10845f..24e003c097 100644 --- a/modules/beast_core/network/beast_MACAddress.h +++ b/modules/beast_core/network/beast_MACAddress.h @@ -24,9 +24,6 @@ #ifndef BEAST_MACADDRESS_H_INCLUDED #define BEAST_MACADDRESS_H_INCLUDED -#include "../containers/beast_Array.h" - - //============================================================================== /** A wrapper for a streaming (TCP) socket. diff --git a/modules/beast_core/network/beast_NamedPipe.h b/modules/beast_core/network/beast_NamedPipe.h index 2db30c294b..2f59ba4a12 100644 --- a/modules/beast_core/network/beast_NamedPipe.h +++ b/modules/beast_core/network/beast_NamedPipe.h @@ -24,8 +24,6 @@ #ifndef BEAST_NAMEDPIPE_H_INCLUDED #define BEAST_NAMEDPIPE_H_INCLUDED -#include "../threads/beast_ReadWriteLock.h" - //============================================================================== /** A cross-process pipe that can have data written to and read from it. diff --git a/modules/beast_core/network/beast_Socket.h b/modules/beast_core/network/beast_Socket.h index 4e8910e51e..734f0c6c6a 100644 --- a/modules/beast_core/network/beast_Socket.h +++ b/modules/beast_core/network/beast_Socket.h @@ -24,9 +24,6 @@ #ifndef BEAST_SOCKET_H_INCLUDED #define BEAST_SOCKET_H_INCLUDED -#include "../text/beast_String.h" - - //============================================================================== /** A wrapper for a streaming (TCP) socket. diff --git a/modules/beast_core/network/beast_URL.h b/modules/beast_core/network/beast_URL.h index 6ddad168c3..589f974f00 100644 --- a/modules/beast_core/network/beast_URL.h +++ b/modules/beast_core/network/beast_URL.h @@ -24,8 +24,6 @@ #ifndef BEAST_URL_H_INCLUDED #define BEAST_URL_H_INCLUDED -#include "../text/beast_StringPairArray.h" -#include "../files/beast_File.h" class InputStream; class XmlElement; diff --git a/modules/beast_core/streams/beast_BufferedInputStream.h b/modules/beast_core/streams/beast_BufferedInputStream.h index 2d3532b871..8f55ee42e8 100644 --- a/modules/beast_core/streams/beast_BufferedInputStream.h +++ b/modules/beast_core/streams/beast_BufferedInputStream.h @@ -24,11 +24,6 @@ #ifndef BEAST_BUFFEREDINPUTSTREAM_H_INCLUDED #define BEAST_BUFFEREDINPUTSTREAM_H_INCLUDED -#include "beast_InputStream.h" -#include "../memory/beast_OptionalScopedPointer.h" -#include "../memory/beast_HeapBlock.h" - - //============================================================================== /** Wraps another input stream, and reads from it using an intermediate buffer diff --git a/modules/beast_core/streams/beast_FileInputSource.h b/modules/beast_core/streams/beast_FileInputSource.h index 99285d6824..63149434c1 100644 --- a/modules/beast_core/streams/beast_FileInputSource.h +++ b/modules/beast_core/streams/beast_FileInputSource.h @@ -24,10 +24,6 @@ #ifndef BEAST_FILEINPUTSOURCE_H_INCLUDED #define BEAST_FILEINPUTSOURCE_H_INCLUDED -#include "beast_InputSource.h" -#include "../files/beast_File.h" - - //============================================================================== /** A type of InputSource that represents a normal file. diff --git a/modules/beast_core/streams/beast_InputSource.h b/modules/beast_core/streams/beast_InputSource.h index 9fdb1c3c9b..ec1c386087 100644 --- a/modules/beast_core/streams/beast_InputSource.h +++ b/modules/beast_core/streams/beast_InputSource.h @@ -24,8 +24,6 @@ #ifndef BEAST_INPUTSOURCE_H_INCLUDED #define BEAST_INPUTSOURCE_H_INCLUDED -#include "beast_InputStream.h" - //============================================================================== /** A lightweight object that can create a stream to read some kind of resource. diff --git a/modules/beast_core/streams/beast_InputStream.cpp b/modules/beast_core/streams/beast_InputStream.cpp index ac47e96991..17360a1e49 100644 --- a/modules/beast_core/streams/beast_InputStream.cpp +++ b/modules/beast_core/streams/beast_InputStream.cpp @@ -192,7 +192,8 @@ String InputStream::readString() } } - return String::fromUTF8 (data, (int) i); + return String (CharPointer_UTF8 (data), + CharPointer_UTF8 (data + i)); } String InputStream::readNextLine() diff --git a/modules/beast_core/streams/beast_InputStream.h b/modules/beast_core/streams/beast_InputStream.h index fb779968d4..3c32dd448d 100644 --- a/modules/beast_core/streams/beast_InputStream.h +++ b/modules/beast_core/streams/beast_InputStream.h @@ -24,10 +24,8 @@ #ifndef BEAST_INPUTSTREAM_H_INCLUDED #define BEAST_INPUTSTREAM_H_INCLUDED -#include "../text/beast_String.h" class MemoryBlock; - //============================================================================== /** The base class for streams that read data. diff --git a/modules/beast_core/streams/beast_MemoryInputStream.h b/modules/beast_core/streams/beast_MemoryInputStream.h index c59773cdaa..24c8c063cf 100644 --- a/modules/beast_core/streams/beast_MemoryInputStream.h +++ b/modules/beast_core/streams/beast_MemoryInputStream.h @@ -24,10 +24,6 @@ #ifndef BEAST_MEMORYINPUTSTREAM_H_INCLUDED #define BEAST_MEMORYINPUTSTREAM_H_INCLUDED -#include "beast_InputStream.h" -#include "../memory/beast_HeapBlock.h" - - //============================================================================== /** Allows a block of data to be accessed as a stream. diff --git a/modules/beast_core/streams/beast_MemoryOutputStream.h b/modules/beast_core/streams/beast_MemoryOutputStream.h index 5072517233..e51f395ebb 100644 --- a/modules/beast_core/streams/beast_MemoryOutputStream.h +++ b/modules/beast_core/streams/beast_MemoryOutputStream.h @@ -24,10 +24,6 @@ #ifndef BEAST_MEMORYOUTPUTSTREAM_H_INCLUDED #define BEAST_MEMORYOUTPUTSTREAM_H_INCLUDED -#include "beast_OutputStream.h" -#include "../memory/beast_MemoryBlock.h" -#include "../memory/beast_ScopedPointer.h" - //============================================================================== /** Writes data to an internal memory buffer, which grows as required. diff --git a/modules/beast_core/streams/beast_OutputStream.h b/modules/beast_core/streams/beast_OutputStream.h index 37024c3d0c..f896568906 100644 --- a/modules/beast_core/streams/beast_OutputStream.h +++ b/modules/beast_core/streams/beast_OutputStream.h @@ -24,13 +24,10 @@ #ifndef BEAST_OUTPUTSTREAM_H_INCLUDED #define BEAST_OUTPUTSTREAM_H_INCLUDED -#include "../text/beast_String.h" -#include "../text/beast_NewLine.h" class InputStream; class MemoryBlock; class File; - //============================================================================== /** The base class for streams that write data to some kind of destination. diff --git a/modules/beast_core/streams/beast_SubregionStream.h b/modules/beast_core/streams/beast_SubregionStream.h index e42ff00555..c61cf7fd8a 100644 --- a/modules/beast_core/streams/beast_SubregionStream.h +++ b/modules/beast_core/streams/beast_SubregionStream.h @@ -24,10 +24,6 @@ #ifndef BEAST_SUBREGIONSTREAM_H_INCLUDED #define BEAST_SUBREGIONSTREAM_H_INCLUDED -#include "beast_InputStream.h" -#include "../memory/beast_OptionalScopedPointer.h" - - //============================================================================== /** Wraps another input stream, and reads from a specific part of it. diff --git a/modules/beast_core/text/beast_CharPointer_UTF16.h b/modules/beast_core/text/beast_CharPointer_UTF16.h index 918fc48c32..6279e48c61 100644 --- a/modules/beast_core/text/beast_CharPointer_UTF16.h +++ b/modules/beast_core/text/beast_CharPointer_UTF16.h @@ -478,6 +478,30 @@ public: byteOrderMarkLE2 = 0xfe }; + /** Returns true if the first pair of bytes in this pointer are the UTF16 byte-order mark (big endian). + The pointer must not be null, and must contain at least two valid bytes. + */ + static bool isByteOrderMarkBigEndian (const void* possibleByteOrder) noexcept + { + bassert (possibleByteOrder != nullptr); + const uint8* const c = static_cast (possibleByteOrder); + + return c[0] == (uint8) byteOrderMarkBE1 + && c[1] == (uint8) byteOrderMarkBE2; + } + + /** Returns true if the first pair of bytes in this pointer are the UTF16 byte-order mark (little endian). + The pointer must not be null, and must contain at least two valid bytes. + */ + static bool isByteOrderMarkLittleEndian (const void* possibleByteOrder) noexcept + { + bassert (possibleByteOrder != nullptr); + const uint8* const c = static_cast (possibleByteOrder); + + return c[0] == (uint8) byteOrderMarkLE1 + && c[1] == (uint8) byteOrderMarkLE2; + } + private: CharType* data; @@ -492,5 +516,4 @@ private: } }; - #endif // BEAST_CHARPOINTER_UTF16_H_INCLUDED diff --git a/modules/beast_core/text/beast_CharPointer_UTF8.h b/modules/beast_core/text/beast_CharPointer_UTF8.h index c35a0b07ba..99ef9a03d9 100644 --- a/modules/beast_core/text/beast_CharPointer_UTF8.h +++ b/modules/beast_core/text/beast_CharPointer_UTF8.h @@ -545,7 +545,7 @@ public: return CharPointer_UTF8 (reinterpret_cast &> (data).exchange (newValue.data)); } - /** These values are the byte-order-mark (BOM) values for a UTF-8 stream. */ + /** These values are the byte-order mark (BOM) values for a UTF-8 stream. */ enum { byteOrderMark1 = 0xef, @@ -553,8 +553,22 @@ public: byteOrderMark3 = 0xbf }; + /** Returns true if the first three bytes in this pointer are the UTF8 byte-order mark (BOM). + The pointer must not be null, and must point to at least 3 valid bytes. + */ + static bool isByteOrderMark (const void* possibleByteOrder) noexcept + { + bassert (possibleByteOrder != nullptr); + const uint8* const c = static_cast (possibleByteOrder); + + return c[0] == (uint8) byteOrderMark1 + && c[1] == (uint8) byteOrderMark2 + && c[2] == (uint8) byteOrderMark3; + } + private: CharType* data; }; -#endif // BEAST_CHARPOINTER_UTF8_H_INCLUDED +#endif + diff --git a/modules/beast_core/text/beast_LocalisedStrings.h b/modules/beast_core/text/beast_LocalisedStrings.h index 8376a9c1cc..be0b0ba43d 100644 --- a/modules/beast_core/text/beast_LocalisedStrings.h +++ b/modules/beast_core/text/beast_LocalisedStrings.h @@ -24,9 +24,6 @@ #ifndef BEAST_LOCALISEDSTRINGS_H_INCLUDED #define BEAST_LOCALISEDSTRINGS_H_INCLUDED -#include "beast_StringPairArray.h" -#include "../files/beast_File.h" - //============================================================================== /** Used to convert strings to localised foreign-language versions. diff --git a/modules/beast_core/text/beast_String.cpp b/modules/beast_core/text/beast_String.cpp index dbaa2f0b5f..5b667b14f5 100644 --- a/modules/beast_core/text/beast_String.cpp +++ b/modules/beast_core/text/beast_String.cpp @@ -481,6 +481,31 @@ void String::append (const String& textToAppend, size_t maxCharsToTake) appendCharPointer (textToAppend.text, maxCharsToTake); } +void String::appendCharPointer (const CharPointerType textToAppend) +{ + appendCharPointer (textToAppend, textToAppend.findTerminatingNull()); +} + +void String::appendCharPointer (const CharPointerType startOfTextToAppend, + const CharPointerType endOfTextToAppend) +{ + bassert (startOfTextToAppend.getAddress() != nullptr && endOfTextToAppend.getAddress() != nullptr); + + const int extraBytesNeeded = getAddressDifference (endOfTextToAppend.getAddress(), + startOfTextToAppend.getAddress()); + bassert (extraBytesNeeded >= 0); + + if (extraBytesNeeded > 0) + { + const size_t byteOffsetOfNull = getByteOffsetOfEnd(); + preallocateBytes (byteOffsetOfNull + (size_t) extraBytesNeeded); + + CharPointerType::CharType* const newStringStart = addBytesToPointer (text.getAddress(), (int) byteOffsetOfNull); + memcpy (newStringStart, startOfTextToAppend.getAddress(), extraBytesNeeded); + CharPointerType (addBytesToPointer (newStringStart, extraBytesNeeded)).writeNull(); + } +} + String& String::operator+= (const wchar_t* const t) { appendCharPointer (castToCharPointer_wchar_t (t)); @@ -1778,9 +1803,9 @@ int String::getHexValue32() const noexcept { return HexConverter ::st int64 String::getHexValue64() const noexcept { return HexConverter::stringToHex (text); } //============================================================================== -String String::createStringFromData (const void* const data_, const int size) +String String::createStringFromData (const void* const unknownData, const int size) { - const uint8* const data = static_cast (data_); + const uint8* const data = static_cast (unknownData); if (size <= 0 || data == nullptr) return empty; @@ -1788,17 +1813,16 @@ String String::createStringFromData (const void* const data_, const int size) if (size == 1) return charToString ((beast_wchar) data[0]); - if ((data[0] == (uint8) CharPointer_UTF16::byteOrderMarkBE1 && data[1] == (uint8) CharPointer_UTF16::byteOrderMarkBE2) - || (data[0] == (uint8) CharPointer_UTF16::byteOrderMarkLE1 && data[1] == (uint8) CharPointer_UTF16::byteOrderMarkLE2)) + if (CharPointer_UTF16::isByteOrderMarkBigEndian (data) + || CharPointer_UTF16::isByteOrderMarkLittleEndian (data)) { - const bool bigEndian = (data[0] == (uint8) CharPointer_UTF16::byteOrderMarkBE1); const int numChars = size / 2 - 1; StringCreationHelper builder ((size_t) numChars); const uint16* const src = (const uint16*) (data + 2); - if (bigEndian) + if (CharPointer_UTF16::isByteOrderMarkBigEndian (data)) { for (int i = 0; i < numChars; ++i) builder.write ((beast_wchar) ByteOrder::swapIfLittleEndian (src[i])); @@ -1814,16 +1838,12 @@ String String::createStringFromData (const void* const data_, const int size) } const uint8* start = data; - const uint8* end = data + size; - if (size >= 3 - && data[0] == (uint8) CharPointer_UTF8::byteOrderMark1 - && data[1] == (uint8) CharPointer_UTF8::byteOrderMark2 - && data[2] == (uint8) CharPointer_UTF8::byteOrderMark3) + if (size >= 3 && CharPointer_UTF8::isByteOrderMark (data)) start += 3; return String (CharPointer_UTF8 ((const char*) start), - CharPointer_UTF8 ((const char*) end)); + CharPointer_UTF8 ((const char*) (data + size))); } //============================================================================== diff --git a/modules/beast_core/text/beast_String.h b/modules/beast_core/text/beast_String.h index aeff8329fa..cda3173fee 100644 --- a/modules/beast_core/text/beast_String.h +++ b/modules/beast_core/text/beast_String.h @@ -200,6 +200,17 @@ public: */ void append (const String& textToAppend, size_t maxCharsToTake); + /** Appends a string to the end of this one. + + @param startOfTextToAppend the start of the string to add. This must not be a nullptr + @param endOfTextToAppend the end of the string to add. This must not be a nullptr + */ + void appendCharPointer (const CharPointerType startOfTextToAppend, + const CharPointerType endOfTextToAppend); + + /** Appends a string to the end of this one. */ + void appendCharPointer (const CharPointerType textToAppend); + /** Appends a string to the end of this one. @param textToAppend the string to add diff --git a/modules/beast_core/text/beast_StringArray.h b/modules/beast_core/text/beast_StringArray.h index 370f076183..5150784707 100644 --- a/modules/beast_core/text/beast_StringArray.h +++ b/modules/beast_core/text/beast_StringArray.h @@ -24,10 +24,6 @@ #ifndef BEAST_STRINGARRAY_H_INCLUDED #define BEAST_STRINGARRAY_H_INCLUDED -#include "beast_String.h" -#include "../containers/beast_Array.h" - - //============================================================================== /** A special array for holding a list of strings. diff --git a/modules/beast_core/text/beast_StringPairArray.h b/modules/beast_core/text/beast_StringPairArray.h index a3acd993ec..141c552265 100644 --- a/modules/beast_core/text/beast_StringPairArray.h +++ b/modules/beast_core/text/beast_StringPairArray.h @@ -24,9 +24,6 @@ #ifndef BEAST_STRINGPAIRARRAY_H_INCLUDED #define BEAST_STRINGPAIRARRAY_H_INCLUDED -#include "beast_StringArray.h" - - //============================================================================== /** A container for holding a set of strings which are keyed by another string. diff --git a/modules/beast_core/text/beast_StringPool.h b/modules/beast_core/text/beast_StringPool.h index aec882aa55..aa311c6682 100644 --- a/modules/beast_core/text/beast_StringPool.h +++ b/modules/beast_core/text/beast_StringPool.h @@ -24,10 +24,6 @@ #ifndef BEAST_STRINGPOOL_H_INCLUDED #define BEAST_STRINGPOOL_H_INCLUDED -#include "beast_String.h" -#include "../containers/beast_Array.h" - - //============================================================================== /** A StringPool holds a set of shared strings, which reduces storage overheads and improves diff --git a/modules/beast_core/threads/beast_CriticalSection.h b/modules/beast_core/threads/beast_CriticalSection.h index d31d01a041..0ccef10423 100644 --- a/modules/beast_core/threads/beast_CriticalSection.h +++ b/modules/beast_core/threads/beast_CriticalSection.h @@ -24,9 +24,6 @@ #ifndef BEAST_CRITICALSECTION_H_INCLUDED #define BEAST_CRITICALSECTION_H_INCLUDED -#include "beast_ScopedLock.h" - - //============================================================================== /** A re-entrant mutex. @@ -114,20 +111,19 @@ public: private: //============================================================================== #if BEAST_WINDOWS - // To avoid including windows.h in the public BEAST headers, we'll just allocate a - // block of memory here that's big enough to be used internally as a windows critical - // section structure. + // To avoid including windows.h in the public Beast headers, we'll just allocate + // a block of memory here that's big enough to be used internally as a windows + // CRITICAL_SECTION structure. #if BEAST_64BIT - uint8 internal [44]; + uint8 section[44]; #else - uint8 internal [24]; + uint8 section[24]; #endif #else - mutable pthread_mutex_t internal; + mutable pthread_mutex_t mutex; #endif }; - //============================================================================== /** A class that can be used in place of a real CriticalSection object, but which diff --git a/modules/beast_core/threads/beast_InterProcessLock.h b/modules/beast_core/threads/beast_InterProcessLock.h index 4582d402de..412550ce05 100644 --- a/modules/beast_core/threads/beast_InterProcessLock.h +++ b/modules/beast_core/threads/beast_InterProcessLock.h @@ -24,10 +24,6 @@ #ifndef BEAST_INTERPROCESSLOCK_H_INCLUDED #define BEAST_INTERPROCESSLOCK_H_INCLUDED -#include "../text/beast_String.h" -#include "../memory/beast_ScopedPointer.h" - - //============================================================================== /** Acts as a critical section which processes can use to block each other. diff --git a/modules/beast_core/threads/beast_Process.h b/modules/beast_core/threads/beast_Process.h index f7f410ba32..d49bd27d7a 100644 --- a/modules/beast_core/threads/beast_Process.h +++ b/modules/beast_core/threads/beast_Process.h @@ -24,9 +24,6 @@ #ifndef BEAST_PROCESS_H_INCLUDED #define BEAST_PROCESS_H_INCLUDED -#include "../text/beast_String.h" - - //============================================================================== /** Represents the current executable's process. diff --git a/modules/beast_core/threads/beast_ReadWriteLock.h b/modules/beast_core/threads/beast_ReadWriteLock.h index 175a824323..e1c0442f94 100644 --- a/modules/beast_core/threads/beast_ReadWriteLock.h +++ b/modules/beast_core/threads/beast_ReadWriteLock.h @@ -24,13 +24,6 @@ #ifndef BEAST_READWRITELOCK_H_INCLUDED #define BEAST_READWRITELOCK_H_INCLUDED -#include "beast_CriticalSection.h" -#include "beast_SpinLock.h" -#include "beast_WaitableEvent.h" -#include "beast_Thread.h" -#include "../containers/beast_Array.h" - - //============================================================================== /** A critical section that allows multiple simultaneous readers. diff --git a/modules/beast_core/threads/beast_ScopedReadLock.h b/modules/beast_core/threads/beast_ScopedReadLock.h index 0285409184..e20b839806 100644 --- a/modules/beast_core/threads/beast_ScopedReadLock.h +++ b/modules/beast_core/threads/beast_ScopedReadLock.h @@ -24,9 +24,6 @@ #ifndef BEAST_SCOPEDREADLOCK_H_INCLUDED #define BEAST_SCOPEDREADLOCK_H_INCLUDED -#include "beast_ReadWriteLock.h" - - //============================================================================== /** Automatically locks and unlocks a ReadWriteLock object. diff --git a/modules/beast_core/threads/beast_ScopedWriteLock.h b/modules/beast_core/threads/beast_ScopedWriteLock.h index 99ad573a9a..9d03482f0b 100644 --- a/modules/beast_core/threads/beast_ScopedWriteLock.h +++ b/modules/beast_core/threads/beast_ScopedWriteLock.h @@ -24,9 +24,6 @@ #ifndef BEAST_SCOPEDWRITELOCK_H_INCLUDED #define BEAST_SCOPEDWRITELOCK_H_INCLUDED -#include "beast_ReadWriteLock.h" - - //============================================================================== /** Automatically locks and unlocks a ReadWriteLock object. diff --git a/modules/beast_core/threads/beast_SpinLock.h b/modules/beast_core/threads/beast_SpinLock.h index e93a1e7504..87b9c2abd2 100644 --- a/modules/beast_core/threads/beast_SpinLock.h +++ b/modules/beast_core/threads/beast_SpinLock.h @@ -24,9 +24,6 @@ #ifndef BEAST_SPINLOCK_H_INCLUDED #define BEAST_SPINLOCK_H_INCLUDED -#include "beast_ScopedLock.h" - - //============================================================================== /** A simple spin-lock class that can be used as a simple, low-overhead mutex for diff --git a/modules/beast_core/threads/beast_Thread.h b/modules/beast_core/threads/beast_Thread.h index 78d85bcfd2..c1e7de8743 100644 --- a/modules/beast_core/threads/beast_Thread.h +++ b/modules/beast_core/threads/beast_Thread.h @@ -24,10 +24,6 @@ #ifndef BEAST_THREAD_H_INCLUDED #define BEAST_THREAD_H_INCLUDED -#include "beast_WaitableEvent.h" -#include "beast_CriticalSection.h" - - //============================================================================== /** Encapsulates a thread. diff --git a/modules/beast_core/threads/beast_ThreadPool.h b/modules/beast_core/threads/beast_ThreadPool.h index cf7ee3ed75..c2c27783a8 100644 --- a/modules/beast_core/threads/beast_ThreadPool.h +++ b/modules/beast_core/threads/beast_ThreadPool.h @@ -24,14 +24,9 @@ #ifndef BEAST_THREADPOOL_H_INCLUDED #define BEAST_THREADPOOL_H_INCLUDED -#include "beast_Thread.h" -#include "../text/beast_StringArray.h" -#include "../containers/beast_Array.h" -#include "../containers/beast_OwnedArray.h" class ThreadPool; class ThreadPoolThread; - //============================================================================== /** A task that is executed by a ThreadPool object. diff --git a/modules/beast_core/threads/beast_TimeSliceThread.h b/modules/beast_core/threads/beast_TimeSliceThread.h index 94b9c684b8..566b398c20 100644 --- a/modules/beast_core/threads/beast_TimeSliceThread.h +++ b/modules/beast_core/threads/beast_TimeSliceThread.h @@ -24,12 +24,8 @@ #ifndef BEAST_TIMESLICETHREAD_H_INCLUDED #define BEAST_TIMESLICETHREAD_H_INCLUDED -#include "beast_Thread.h" -#include "../containers/beast_Array.h" -#include "../time/beast_Time.h" class TimeSliceThread; - //============================================================================== /** Used by the TimeSliceThread class. diff --git a/modules/beast_core/threads/beast_WaitableEvent.h b/modules/beast_core/threads/beast_WaitableEvent.h index 5b8f47a70e..8cbb68c840 100644 --- a/modules/beast_core/threads/beast_WaitableEvent.h +++ b/modules/beast_core/threads/beast_WaitableEvent.h @@ -24,9 +24,6 @@ #ifndef BEAST_WAITABLEEVENT_H_INCLUDED #define BEAST_WAITABLEEVENT_H_INCLUDED -#include "../text/beast_String.h" - - //============================================================================== /** Allows threads to wait for events triggered by other threads. @@ -103,7 +100,7 @@ public: private: //============================================================================== #if BEAST_WINDOWS - void* internal; + void* handle; #else mutable pthread_cond_t condition; mutable pthread_mutex_t mutex; diff --git a/modules/beast_core/time/beast_PerformanceCounter.h b/modules/beast_core/time/beast_PerformanceCounter.h index 8063d60fbc..504dd2f126 100644 --- a/modules/beast_core/time/beast_PerformanceCounter.h +++ b/modules/beast_core/time/beast_PerformanceCounter.h @@ -24,9 +24,6 @@ #ifndef BEAST_PERFORMANCECOUNTER_H_INCLUDED #define BEAST_PERFORMANCECOUNTER_H_INCLUDED -#include "../files/beast_File.h" - - //============================================================================== /** A timer for measuring performance of code and dumping the results to a file. diff --git a/modules/beast_core/time/beast_RelativeTime.h b/modules/beast_core/time/beast_RelativeTime.h index e26cd086bc..ed8c1f3ff2 100644 --- a/modules/beast_core/time/beast_RelativeTime.h +++ b/modules/beast_core/time/beast_RelativeTime.h @@ -24,9 +24,6 @@ #ifndef BEAST_RELATIVETIME_H_INCLUDED #define BEAST_RELATIVETIME_H_INCLUDED -#include "../text/beast_String.h" - - //============================================================================== /** A relative measure of time. diff --git a/modules/beast_core/time/beast_Time.h b/modules/beast_core/time/beast_Time.h index e2420630ca..037f18092b 100644 --- a/modules/beast_core/time/beast_Time.h +++ b/modules/beast_core/time/beast_Time.h @@ -24,9 +24,6 @@ #ifndef BEAST_TIME_H_INCLUDED #define BEAST_TIME_H_INCLUDED -#include "beast_RelativeTime.h" - - //============================================================================== /** Holds an absolute date and time. diff --git a/modules/beast_core/xml/beast_XmlDocument.cpp b/modules/beast_core/xml/beast_XmlDocument.cpp index 657a47cbc8..9e2db7496a 100644 --- a/modules/beast_core/xml/beast_XmlDocument.cpp +++ b/modules/beast_core/xml/beast_XmlDocument.cpp @@ -24,12 +24,18 @@ XmlDocument::XmlDocument (const String& documentText) : originalText (documentText), input (nullptr), + outOfData (false), + errorOccurred (false), + needToLoadDTD (false), ignoreEmptyTextElements (true) { } XmlDocument::XmlDocument (const File& file) : input (nullptr), + outOfData (false), + errorOccurred (false), + needToLoadDTD (false), ignoreEmptyTextElements (true), inputSource (new FileInputSource (file)) { @@ -77,68 +83,69 @@ namespace XmlIdentifierChars : isIdentifierCharSlow (c); } - /*static void generateIdentifierCharConstants() + /* + static void generateIdentifierCharConstants() { uint32 n[8] = { 0 }; for (int i = 0; i < 256; ++i) - if (isIdentifierCharSlow (i)) - n[i >> 5] |= (1 << (i & 31)); + if (isIdentifierCharSlow (i)) + n[i >> 5] |= (1 << (i & 31)); String s; for (int i = 0; i < 8; ++i) s << "0x" << String::toHexString ((int) n[i]) << ", "; DBG (s); - }*/ + } + */ + + static String::CharPointerType findEndOfToken (String::CharPointerType p) + { + while (isIdentifierChar (*p)) + ++p; + + return p; + } } XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement) { - String textToParse (originalText); - - if (textToParse.isEmpty() && inputSource != nullptr) + if (originalText.isEmpty() && inputSource != nullptr) { - ScopedPointer in (inputSource->createInputStream()); + ScopedPointer in (inputSource->createInputStream()); if (in != nullptr) { MemoryOutputStream data; data.writeFromInputStream (*in, onlyReadOuterDocumentElement ? 8192 : -1); - textToParse = data.toString(); - if (! onlyReadOuterDocumentElement) - originalText = textToParse; + #if BEAST_STRING_UTF_TYPE == 8 + if (data.getDataSize() > 2) + { + data.writeByte (0); + const char* text = static_cast (data.getData()); + + if (CharPointer_UTF16::isByteOrderMarkBigEndian (text) + || CharPointer_UTF16::isByteOrderMarkLittleEndian (text)) + { + originalText = data.toString(); + } + else + { + if (CharPointer_UTF8::isByteOrderMark (text)) + text += 3; + + // parse the input buffer directly to avoid copying it all to a string.. + return parseDocumentElement (String::CharPointerType (text), onlyReadOuterDocumentElement); + } + } + #else + originalText = data.toString(); + #endif } } - input = textToParse.getCharPointer(); - lastError = String::empty; - errorOccurred = false; - outOfData = false; - needToLoadDTD = true; - - if (textToParse.isEmpty()) - { - lastError = "not enough input"; - } - else - { - skipHeader(); - - if (input.getAddress() != nullptr) - { - ScopedPointer result (readNextElement (! onlyReadOuterDocumentElement)); - - if (! errorOccurred) - return result.release(); - } - else - { - lastError = "incorrect xml header"; - } - } - - return nullptr; + return parseDocumentElement (originalText.getCharPointer(), onlyReadOuterDocumentElement); } const String& XmlDocument::getLastParseError() const noexcept @@ -156,7 +163,7 @@ String XmlDocument::getFileContents (const String& filename) const { if (inputSource != nullptr) { - const ScopedPointer in (inputSource->createInputStreamFor (filename.trim().unquoted())); + const ScopedPointer in (inputSource->createInputStreamFor (filename.trim().unquoted())); if (in != nullptr) return in->readEntireStreamAsString(); @@ -178,33 +185,56 @@ beast_wchar XmlDocument::readNextChar() noexcept return c; } -int XmlDocument::findNextTokenLength() noexcept +XmlElement* XmlDocument::parseDocumentElement (String::CharPointerType textToParse, + const bool onlyReadOuterDocumentElement) { - int len = 0; - beast_wchar c = *input; + input = textToParse; + errorOccurred = false; + outOfData = false; + needToLoadDTD = true; - while (XmlIdentifierChars::isIdentifierChar (c)) - c = input [++len]; + if (textToParse.isEmpty()) + { + lastError = "not enough input"; + } + else if (! parseHeader()) + { + lastError = "malformed header"; + } + else if (! parseDTD()) + { + lastError = "malformed DTD"; + } + else + { + lastError = String::empty; - return len; + ScopedPointer result (readNextElement (! onlyReadOuterDocumentElement)); + + if (! errorOccurred) + return result.release(); + } + + return nullptr; } -void XmlDocument::skipHeader() +bool XmlDocument::parseHeader() { - const int headerStart = input.indexOf (CharPointer_UTF8 ("= 0) + if (CharacterFunctions::compareUpTo (input, CharPointer_ASCII ("")); - if (headerEnd < 0) - return; + const String::CharPointerType headerEnd (CharacterFunctions::find (input, CharPointer_ASCII ("?>"))); + + if (headerEnd.isEmpty()) + return false; #if BEAST_DEBUG - const String header (input + headerStart, (size_t) (headerEnd - headerStart)); - const String encoding (header.fromFirstOccurrenceOf ("encoding", false, true) - .fromFirstOccurrenceOf ("=", false, false) - .fromFirstOccurrenceOf ("\"", false, false) - .upToFirstOccurrenceOf ("\"", false, false).trim()); + const String encoding (String (input, headerEnd) + .fromFirstOccurrenceOf ("encoding", false, true) + .fromFirstOccurrenceOf ("=", false, false) + .fromFirstOccurrenceOf ("\"", false, false) + .upToFirstOccurrenceOf ("\"", false, false).trim()); /* If you load an XML document with a non-UTF encoding type, it may have been loaded wrongly.. Since all the files are read via the normal beast file streams, @@ -216,58 +246,59 @@ void XmlDocument::skipHeader() bassert (encoding.isEmpty() || encoding.startsWithIgnoreCase ("utf-")); #endif - input += headerEnd + 2; + input = headerEnd + 2; + skipNextWhiteSpace(); } - skipNextWhiteSpace(); + return true; +} - const int docTypeIndex = input.indexOf (CharPointer_UTF8 (" 0) +bool XmlDocument::parseDTD() +{ + if (CharacterFunctions::compareUpTo (input, CharPointer_ASCII (" 0;) + { + const beast_wchar c = readNextChar(); - if (c == '<') - ++n; - else if (c == '>') - --n; + if (outOfData) + return false; + + if (c == '<') + ++n; + else if (c == '>') + --n; + } + + dtdText = String (dtdStart, input - 1).trim(); } - dtdText = String (docType, (size_t) (input.getAddress() - (docType.getAddress() + 1))).trim(); + return true; } void XmlDocument::skipNextWhiteSpace() { for (;;) { - beast_wchar c = *input; + input = input.findEndOfWhitespace(); - while (CharacterFunctions::isWhitespace (c)) - c = *++input; - - if (c == 0) + if (input.isEmpty()) { outOfData = true; break; } - else if (c == '<') + + if (*input == '<') { if (input[1] == '!' && input[2] == '-' && input[3] == '-') { input += 4; - const int closeComment = input.indexOf (CharPointer_UTF8 ("-->")); + const int closeComment = input.indexOf (CharPointer_ASCII ("-->")); if (closeComment < 0) { @@ -278,10 +309,11 @@ void XmlDocument::skipNextWhiteSpace() input += closeComment + 3; continue; } - else if (input[1] == '?') + + if (input[1] == '?') { input += 2; - const int closeBracket = input.indexOf (CharPointer_UTF8 ("?>")); + const int closeBracket = input.indexOf (CharPointer_ASCII ("?>")); if (closeBracket < 0) { @@ -318,7 +350,6 @@ void XmlDocument::readQuotedString (String& result) else { const String::CharPointerType start (input); - size_t numChars = 0; for (;;) { @@ -326,13 +357,13 @@ void XmlDocument::readQuotedString (String& result) if (character == quote) { - result.appendCharPointer (start, numChars); + result.appendCharPointer (start, input); ++input; return; } else if (character == '&') { - result.appendCharPointer (start, numChars); + result.appendCharPointer (start, input); break; } else if (character == 0) @@ -343,7 +374,6 @@ void XmlDocument::readQuotedString (String& result) } ++input; - ++numChars; } } } @@ -357,28 +387,26 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) if (outOfData) return nullptr; - const int openBracket = input.indexOf ((beast_wchar) '<'); - - if (openBracket >= 0) + if (*input == '<') { - input += openBracket + 1; - int tagLen = findNextTokenLength(); + ++input; + String::CharPointerType endOfToken (XmlIdentifierChars::findEndOfToken (input)); - if (tagLen == 0) + if (endOfToken == input) { // no tag name - but allow for a gap after the '<' before giving an error skipNextWhiteSpace(); - tagLen = findNextTokenLength(); + endOfToken = XmlIdentifierChars::findEndOfToken (input); - if (tagLen == 0) + if (endOfToken == input) { setLastError ("tag name missing", false); return node; } } - node = new XmlElement (String (input, (size_t) tagLen)); - input += tagLen; + node = new XmlElement (String (input, endOfToken)); + input = endOfToken; LinkedListPointer::Appender attributeAppender (node->attributes); // look for attributes @@ -409,12 +437,12 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) // get an attribute.. if (XmlIdentifierChars::isIdentifierChar (c)) { - const int attNameLen = findNextTokenLength(); + String::CharPointerType attNameEnd (XmlIdentifierChars::findEndOfToken (input)); - if (attNameLen > 0) + if (attNameEnd != input) { const String::CharPointerType attNameStart (input); - input += attNameLen; + input = attNameEnd; skipNextWhiteSpace(); @@ -427,7 +455,7 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) if (nextChar == '"' || nextChar == '\'') { XmlElement::XmlAttributeNode* const newAtt - = new XmlElement::XmlAttributeNode (String (attNameStart, (size_t) attNameLen), + = new XmlElement::XmlAttributeNode (String (attNameStart, attNameEnd), String::empty); readQuotedString (newAtt->value); @@ -435,6 +463,12 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) continue; } } + else + { + setLastError ("expected '=' after attribute '" + + String (attNameStart, attNameEnd) + "'", false); + return node; + } } } else @@ -467,7 +501,9 @@ void XmlDocument::readChildElements (XmlElement* parent) if (*input == '<') { - if (input[1] == '/') + const beast_wchar c1 = input[1]; + + if (c1 == '/') { // our close tag.. const int closeTag = input.indexOf ((beast_wchar) '>'); @@ -477,41 +513,33 @@ void XmlDocument::readChildElements (XmlElement* parent) break; } - else if (input[1] == '!' - && input[2] == '[' - && input[3] == 'C' - && input[4] == 'D' - && input[5] == 'A' - && input[6] == 'T' - && input[7] == 'A' - && input[8] == '[') + + if (c1 == '!' && CharacterFunctions::compareUpTo (input + 2, CharPointer_ASCII ("[CDATA["), 7) == 0) { input += 9; const String::CharPointerType inputStart (input); - size_t len = 0; - for (;;) { - if (*input == 0) + const beast_wchar c0 = *input; + + if (c0 == 0) { setLastError ("unterminated CDATA section", false); outOfData = true; break; } - else if (input[0] == ']' + else if (c0 == ']' && input[1] == ']' && input[2] == '>') { + childAppender.append (XmlElement::createTextElement (String (inputStart, input))); input += 3; break; } ++input; - ++len; } - - childAppender.append (XmlElement::createTextElement (String (inputStart, len))); } else { @@ -522,7 +550,7 @@ void XmlDocument::readChildElements (XmlElement* parent) break; } } - else // must be a character block + else // must be a character block { input = preWhitespaceInput; // roll back to include the leading whitespace String textElementContent; @@ -575,17 +603,15 @@ void XmlDocument::readChildElements (XmlElement* parent) else { const String::CharPointerType start (input); - size_t len = 0; for (;;) { const beast_wchar nextChar = *input; if (nextChar == '<' || nextChar == '&') - { break; - } - else if (nextChar == 0) + + if (nextChar == 0) { setLastError ("unmatched tags", false); outOfData = true; @@ -593,17 +619,14 @@ void XmlDocument::readChildElements (XmlElement* parent) } ++input; - ++len; } - textElementContent.appendCharPointer (start, len); + textElementContent.appendCharPointer (start, input); } } if ((! ignoreEmptyTextElements) || textElementContent.containsNonWhitespaceChars()) - { childAppender.append (XmlElement::createTextElement (textElementContent)); - } } } } @@ -613,27 +636,27 @@ void XmlDocument::readEntity (String& result) // skip over the ampersand ++input; - if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("amp;"), 4) == 0) + if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("amp;"), 4) == 0) { input += 4; result += '&'; } - else if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("quot;"), 5) == 0) + else if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("quot;"), 5) == 0) { input += 5; result += '"'; } - else if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("apos;"), 5) == 0) + else if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("apos;"), 5) == 0) { input += 5; result += '\''; } - else if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("lt;"), 3) == 0) + else if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("lt;"), 3) == 0) { input += 3; result += '<'; } - else if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("gt;"), 3) == 0) + else if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("gt;"), 3) == 0) { input += 3; result += '>'; @@ -712,11 +735,11 @@ void XmlDocument::readEntity (String& result) String XmlDocument::expandEntity (const String& ent) { - if (ent.equalsIgnoreCase ("amp")) return String::charToString ('&'); - if (ent.equalsIgnoreCase ("quot")) return String::charToString ('"'); - if (ent.equalsIgnoreCase ("apos")) return String::charToString ('\''); - if (ent.equalsIgnoreCase ("lt")) return String::charToString ('<'); - if (ent.equalsIgnoreCase ("gt")) return String::charToString ('>'); + if (ent.equalsIgnoreCase ("amp")) return String::charToString ('&'); + if (ent.equalsIgnoreCase ("quot")) return String::charToString ('"'); + if (ent.equalsIgnoreCase ("apos")) return String::charToString ('\''); + if (ent.equalsIgnoreCase ("lt")) return String::charToString ('<'); + if (ent.equalsIgnoreCase ("gt")) return String::charToString ('>'); if (ent[0] == '#') { @@ -845,4 +868,4 @@ String XmlDocument::getParameterEntity (const String& entity) } return entity; -} +} \ No newline at end of file diff --git a/modules/beast_core/xml/beast_XmlDocument.h b/modules/beast_core/xml/beast_XmlDocument.h index 0802b8018a..5e9a85692b 100644 --- a/modules/beast_core/xml/beast_XmlDocument.h +++ b/modules/beast_core/xml/beast_XmlDocument.h @@ -24,13 +24,6 @@ #ifndef BEAST_XMLDOCUMENT_H_INCLUDED #define BEAST_XMLDOCUMENT_H_INCLUDED -#include "beast_XmlElement.h" -#include "../text/beast_StringArray.h" -#include "../files/beast_File.h" -#include "../memory/beast_ScopedPointer.h" -class InputSource; - - //============================================================================== /** Parses a text-based XML document and creates an XmlElement object from it. @@ -150,6 +143,22 @@ public: //============================================================================== private: + XmlElement* parseDocumentElement (String::CharPointerType, bool outer); + void setLastError (const String& desc, bool carryOn); + bool parseHeader(); + bool parseDTD(); + void skipNextWhiteSpace(); + beast_wchar readNextChar() noexcept; + XmlElement* readNextElement (bool alsoParseSubElements); + void readChildElements (XmlElement* parent); + void readQuotedString (String& result); + void readEntity (String& result); + + String getFileContents (const String& filename) const; + String expandEntity (const String& entity); + String expandExternalEntity (const String& entity); + String getParameterEntity (const String& entity); + String originalText; String::CharPointerType input; bool outOfData, errorOccurred; @@ -158,22 +167,7 @@ private: StringArray tokenisedDTD; bool needToLoadDTD, ignoreEmptyTextElements; ScopedPointer inputSource; - - void setLastError (const String& desc, bool carryOn); - void skipHeader(); - void skipNextWhiteSpace(); - beast_wchar readNextChar() noexcept; - XmlElement* readNextElement (bool alsoParseSubElements); - void readChildElements (XmlElement* parent); - int findNextTokenLength() noexcept; - void readQuotedString (String& result); - void readEntity (String& result); - - String getFileContents (const String& filename) const; - String expandEntity (const String& entity); - String expandExternalEntity (const String& entity); - String getParameterEntity (const String& entity); }; +#endif -#endif // BEAST_XMLDOCUMENT_H_INCLUDED diff --git a/modules/beast_core/xml/beast_XmlElement.cpp b/modules/beast_core/xml/beast_XmlElement.cpp index 5c48d9f57d..7487075086 100644 --- a/modules/beast_core/xml/beast_XmlElement.cpp +++ b/modules/beast_core/xml/beast_XmlElement.cpp @@ -465,10 +465,7 @@ bool XmlElement::getBoolAttribute (const String& attributeName, const bool defau { if (att->hasName (attributeName)) { - beast_wchar firstChar = att->value[0]; - - if (CharacterFunctions::isWhitespace (firstChar)) - firstChar = att->value.trimStart() [0]; + const beast_wchar firstChar = *(att->value.getCharPointer().findEndOfWhitespace()); return firstChar == '1' || firstChar == 't' @@ -526,7 +523,7 @@ void XmlElement::setAttribute (const String& attributeName, const int number) void XmlElement::setAttribute (const String& attributeName, const double number) { - setAttribute (attributeName, String (number)); + setAttribute (attributeName, String (number, 20)); } void XmlElement::removeAttribute (const String& attributeName) noexcept @@ -786,7 +783,7 @@ String XmlElement::getAllSubText() const for (const XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem) mem << child->getAllSubText(); - return mem.toString(); + return mem.toUTF8(); } String XmlElement::getChildElementAllSubText (const String& childTagName, diff --git a/modules/beast_core/xml/beast_XmlElement.h b/modules/beast_core/xml/beast_XmlElement.h index 9a453f88cc..58c3125ad5 100644 --- a/modules/beast_core/xml/beast_XmlElement.h +++ b/modules/beast_core/xml/beast_XmlElement.h @@ -24,12 +24,6 @@ #ifndef BEAST_XMLELEMENT_H_INCLUDED #define BEAST_XMLELEMENT_H_INCLUDED -#include "../text/beast_String.h" -#include "../streams/beast_OutputStream.h" -#include "../files/beast_File.h" -#include "../containers/beast_LinkedListPointer.h" - - //============================================================================== /** A handy macro to make it easy to iterate all the child elements in an XmlElement. diff --git a/modules/beast_core/zip/beast_GZIPCompressorOutputStream.h b/modules/beast_core/zip/beast_GZIPCompressorOutputStream.h index 466747da6a..88a0e25cef 100644 --- a/modules/beast_core/zip/beast_GZIPCompressorOutputStream.h +++ b/modules/beast_core/zip/beast_GZIPCompressorOutputStream.h @@ -29,11 +29,6 @@ #ifndef BEAST_GZIPCOMPRESSOROUTPUTSTREAM_H_INCLUDED #define BEAST_GZIPCOMPRESSOROUTPUTSTREAM_H_INCLUDED -#include "../streams/beast_OutputStream.h" -#include "../memory/beast_OptionalScopedPointer.h" -#include "../memory/beast_HeapBlock.h" - - //============================================================================== /** A stream which uses zlib to compress the data written into it. diff --git a/modules/beast_core/zip/beast_GZIPDecompressorInputStream.h b/modules/beast_core/zip/beast_GZIPDecompressorInputStream.h index 47c7afb379..14a525f394 100644 --- a/modules/beast_core/zip/beast_GZIPDecompressorInputStream.h +++ b/modules/beast_core/zip/beast_GZIPDecompressorInputStream.h @@ -29,11 +29,6 @@ #ifndef BEAST_GZIPDECOMPRESSORINPUTSTREAM_H_INCLUDED #define BEAST_GZIPDECOMPRESSORINPUTSTREAM_H_INCLUDED -#include "../streams/beast_InputStream.h" -#include "../memory/beast_OptionalScopedPointer.h" -#include "../memory/beast_HeapBlock.h" - - //============================================================================== /** This stream will decompress a source-stream using zlib. diff --git a/modules/beast_core/zip/beast_ZipFile.h b/modules/beast_core/zip/beast_ZipFile.h index 881cae8d80..7fd08b10be 100644 --- a/modules/beast_core/zip/beast_ZipFile.h +++ b/modules/beast_core/zip/beast_ZipFile.h @@ -29,12 +29,6 @@ #ifndef BEAST_ZIPFILE_H_INCLUDED #define BEAST_ZIPFILE_H_INCLUDED -#include "../files/beast_File.h" -#include "../streams/beast_InputSource.h" -#include "../threads/beast_CriticalSection.h" -#include "../containers/beast_OwnedArray.h" - - //============================================================================== /** Decodes a ZIP file from a stream. diff --git a/modules/beast_sqdb/api/type_conversion_traits.h b/modules/beast_sqdb/api/type_conversion_traits.h index e81a7319d3..7742051d4a 100644 --- a/modules/beast_sqdb/api/type_conversion_traits.h +++ b/modules/beast_sqdb/api/type_conversion_traits.h @@ -96,7 +96,7 @@ struct type_conversion