mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 12:05:53 +00:00
General beast update, fixes, optimizations, features:
* Clean ups, optimizations, and new File::commonDocumentsDirectory enum * Replace sortArray with std::sort for performance * More error tolerance in XML parser, speedups * Refactor some byte-order mark detection code * Add String::appendCharPointer overloads * More XML parser optimisations and better error detection * Misc performance tweaks * Fixes for support of non utf8 strings * Increased precision when storing strings in XmlElement * Minor clean-ups * Minor fix to XmlDocument * Cleanups to CriticalSection and related synchronization primitives * Fix DynamicArray unit test
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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 <int> (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 <int> (numberToMutate) + ")";
|
||||
beginTestCase (s);
|
||||
@@ -141,6 +143,7 @@ public:
|
||||
step ++;
|
||||
iter - v.rend ();
|
||||
}
|
||||
pass ();
|
||||
}
|
||||
|
||||
{
|
||||
@@ -152,6 +155,7 @@ public:
|
||||
step ++;
|
||||
iter - v.crend ();
|
||||
}
|
||||
pass ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <class OtherArrayType>
|
||||
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 <class OtherArrayType>
|
||||
void removeValuesNotIn (const OtherArrayType& otherArray)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
#ifndef BEAST_DYNAMICOBJECT_H_INCLUDED
|
||||
#define BEAST_DYNAMICOBJECT_H_INCLUDED
|
||||
|
||||
#include "beast_NamedValueSet.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Represents a dynamically implemented object.
|
||||
|
||||
@@ -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 <typename ElementComparator>
|
||||
struct SortFunctionConverter
|
||||
{
|
||||
SortFunctionConverter (ElementComparator& e) : comparator (e) {}
|
||||
|
||||
template <typename Type>
|
||||
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<ElementComparator> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::stable_sort (array + firstElement, array + lastElement + 1, converter);
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
std::sort (array + firstElement, array + lastElement + 1, converter);
|
||||
}
|
||||
|
||||
|
||||
@@ -270,5 +185,5 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // BEAST_ELEMENTCOMPARATOR_H_INCLUDED
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -57,10 +57,6 @@ File::File (const File& other)
|
||||
{
|
||||
}
|
||||
|
||||
File::~File() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
File File::createFileWithoutCheckingPath (const String& path) noexcept
|
||||
{
|
||||
File f;
|
||||
|
||||
@@ -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 <File>
|
||||
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.
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#ifndef BEAST_MEMORYMAPPEDFILE_H_INCLUDED
|
||||
#define BEAST_MEMORYMAPPEDFILE_H_INCLUDED
|
||||
|
||||
#include "beast_File.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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
#ifndef BEAST_RANDOM_H_INCLUDED
|
||||
#define BEAST_RANDOM_H_INCLUDED
|
||||
|
||||
#include "beast_BigInteger.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A random number generator.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <char> data;
|
||||
size_t size;
|
||||
static const char* const encodingTable;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // BEAST_MEMORYBLOCK_H_INCLUDED
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -162,12 +162,11 @@ 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");
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
static_bassert (sizeof (CRITICAL_SECTION) <= 24);
|
||||
#else
|
||||
static_bassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
|
||||
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;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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<const uint8*> (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<const uint8*> (possibleByteOrder);
|
||||
|
||||
return c[0] == (uint8) byteOrderMarkLE1
|
||||
&& c[1] == (uint8) byteOrderMarkLE2;
|
||||
}
|
||||
|
||||
private:
|
||||
CharType* data;
|
||||
|
||||
@@ -492,5 +516,4 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // BEAST_CHARPOINTER_UTF16_H_INCLUDED
|
||||
|
||||
@@ -545,7 +545,7 @@ public:
|
||||
return CharPointer_UTF8 (reinterpret_cast <Atomic<CharType*>&> (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<const uint8*> (possibleByteOrder);
|
||||
|
||||
return c[0] == (uint8) byteOrderMark1
|
||||
&& c[1] == (uint8) byteOrderMark2
|
||||
&& c[2] == (uint8) byteOrderMark3;
|
||||
}
|
||||
|
||||
private:
|
||||
CharType* data;
|
||||
};
|
||||
|
||||
#endif // BEAST_CHARPOINTER_UTF8_H_INCLUDED
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<int> ::st
|
||||
int64 String::getHexValue64() const noexcept { return HexConverter<int64>::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 <const uint8*> (data_);
|
||||
const uint8* const data = static_cast<const uint8*> (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)));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
#ifndef BEAST_RELATIVETIME_H_INCLUDED
|
||||
#define BEAST_RELATIVETIME_H_INCLUDED
|
||||
|
||||
#include "../text/beast_String.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/** A relative measure of time.
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
#ifndef BEAST_TIME_H_INCLUDED
|
||||
#define BEAST_TIME_H_INCLUDED
|
||||
|
||||
#include "beast_RelativeTime.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Holds an absolute date and time.
|
||||
|
||||
@@ -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,7 +83,8 @@ namespace XmlIdentifierChars
|
||||
: isIdentifierCharSlow (c);
|
||||
}
|
||||
|
||||
/*static void generateIdentifierCharConstants()
|
||||
/*
|
||||
static void generateIdentifierCharConstants()
|
||||
{
|
||||
uint32 n[8] = { 0 };
|
||||
for (int i = 0; i < 256; ++i)
|
||||
@@ -89,56 +96,56 @@ namespace XmlIdentifierChars
|
||||
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 <InputStream> in (inputSource->createInputStream());
|
||||
ScopedPointer<InputStream> in (inputSource->createInputStream());
|
||||
|
||||
if (in != nullptr)
|
||||
{
|
||||
MemoryOutputStream data;
|
||||
data.writeFromInputStream (*in, onlyReadOuterDocumentElement ? 8192 : -1);
|
||||
textToParse = data.toString();
|
||||
|
||||
if (! onlyReadOuterDocumentElement)
|
||||
originalText = textToParse;
|
||||
}
|
||||
}
|
||||
|
||||
input = textToParse.getCharPointer();
|
||||
lastError = String::empty;
|
||||
errorOccurred = false;
|
||||
outOfData = false;
|
||||
needToLoadDTD = true;
|
||||
|
||||
if (textToParse.isEmpty())
|
||||
#if BEAST_STRING_UTF_TYPE == 8
|
||||
if (data.getDataSize() > 2)
|
||||
{
|
||||
lastError = "not enough input";
|
||||
data.writeByte (0);
|
||||
const char* text = static_cast<const char*> (data.getData());
|
||||
|
||||
if (CharPointer_UTF16::isByteOrderMarkBigEndian (text)
|
||||
|| CharPointer_UTF16::isByteOrderMarkLittleEndian (text))
|
||||
{
|
||||
originalText = data.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
skipHeader();
|
||||
if (CharPointer_UTF8::isByteOrderMark (text))
|
||||
text += 3;
|
||||
|
||||
if (input.getAddress() != nullptr)
|
||||
{
|
||||
ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
|
||||
|
||||
if (! errorOccurred)
|
||||
return result.release();
|
||||
// parse the input buffer directly to avoid copying it all to a string..
|
||||
return parseDocumentElement (String::CharPointerType (text), onlyReadOuterDocumentElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
lastError = "incorrect xml header";
|
||||
}
|
||||
#else
|
||||
originalText = data.toString();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
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 <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
|
||||
const ScopedPointer<InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
|
||||
|
||||
if (in != nullptr)
|
||||
return in->readEntireStreamAsString();
|
||||
@@ -178,30 +185,53 @@ 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<XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
|
||||
|
||||
if (! errorOccurred)
|
||||
return result.release();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void XmlDocument::skipHeader()
|
||||
bool XmlDocument::parseHeader()
|
||||
{
|
||||
const int headerStart = input.indexOf (CharPointer_UTF8 ("<?xml"));
|
||||
skipNextWhiteSpace();
|
||||
|
||||
if (headerStart >= 0)
|
||||
if (CharacterFunctions::compareUpTo (input, CharPointer_ASCII ("<?xml"), 5) == 0)
|
||||
{
|
||||
const int headerEnd = (input + headerStart).indexOf (CharPointer_UTF8 ("?>"));
|
||||
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)
|
||||
const String encoding (String (input, headerEnd)
|
||||
.fromFirstOccurrenceOf ("encoding", false, true)
|
||||
.fromFirstOccurrenceOf ("=", false, false)
|
||||
.fromFirstOccurrenceOf ("\"", false, false)
|
||||
.upToFirstOccurrenceOf ("\"", false, false).trim());
|
||||
@@ -216,26 +246,26 @@ 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 ("<!DOCTYPE"));
|
||||
if (docTypeIndex < 0)
|
||||
return;
|
||||
bool XmlDocument::parseDTD()
|
||||
{
|
||||
if (CharacterFunctions::compareUpTo (input, CharPointer_ASCII ("<!DOCTYPE"), 9) == 0)
|
||||
{
|
||||
input += 9;
|
||||
const String::CharPointerType dtdStart (input);
|
||||
|
||||
input += docTypeIndex + 9;
|
||||
const String::CharPointerType docType (input);
|
||||
|
||||
int n = 1;
|
||||
|
||||
while (n > 0)
|
||||
for (int n = 1; n > 0;)
|
||||
{
|
||||
const beast_wchar c = readNextChar();
|
||||
|
||||
if (outOfData)
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (c == '<')
|
||||
++n;
|
||||
@@ -243,31 +273,32 @@ void XmlDocument::skipHeader()
|
||||
--n;
|
||||
}
|
||||
|
||||
dtdText = String (docType, (size_t) (input.getAddress() - (docType.getAddress() + 1))).trim();
|
||||
dtdText = String (dtdStart, input - 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<XmlElement::XmlAttributeNode>::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
|
||||
{
|
||||
@@ -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,19 +619,16 @@ void XmlDocument::readChildElements (XmlElement* parent)
|
||||
}
|
||||
|
||||
++input;
|
||||
++len;
|
||||
}
|
||||
|
||||
textElementContent.appendCharPointer (start, len);
|
||||
textElementContent.appendCharPointer (start, input);
|
||||
}
|
||||
}
|
||||
|
||||
if ((! ignoreEmptyTextElements) || textElementContent.containsNonWhitespaceChars())
|
||||
{
|
||||
childAppender.append (XmlElement::createTextElement (textElementContent));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XmlDocument::readEntity (String& result)
|
||||
@@ -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 += '>';
|
||||
|
||||
@@ -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> 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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -96,7 +96,7 @@ struct type_conversion <Time>
|
||||
{
|
||||
if (ind == i_null)
|
||||
{
|
||||
// jassertfalse
|
||||
// bassertfalse
|
||||
result = Time(0);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -68,7 +68,7 @@ const Error sqliteError(const char* sourceFileName,
|
||||
int sqliteErrorCode)
|
||||
{
|
||||
/*
|
||||
jassert (sqliteErrorCode != SQLITE_ROW &&
|
||||
bassert (sqliteErrorCode != SQLITE_ROW &&
|
||||
sqliteErrorCode != SQLITE_DONE);
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user