35 return character ==
':'
37 || (character >=
'a' && character <=
'z')
38 || (character >=
'A' && character <=
'Z')
39 || (character >= 0xc0 && character <= 0xd6)
40 || (character >= 0xd8 && character <= 0xf6)
41 || (character >= 0xf8 && character <= 0x2ff)
42 || (character >= 0x370 && character <= 0x37d)
43 || (character >= 0x37f && character <= 0x1fff)
44 || (character >= 0x200c && character <= 0x200d)
45 || (character >= 0x2070 && character <= 0x218f)
46 || (character >= 0x2c00 && character <= 0x2fef)
47 || (character >= 0x3001 && character <= 0xd7ff)
48 || (character >= 0xf900 && character <= 0xfdcf)
49 || (character >= 0xfdf0 && character <= 0xfffd)
50 || (character >= 0x10000 && character <= 0xeffff);
59 || (character >=
'0' && character <=
'9')
60 || (character >= 0x300 && character <= 0x036f)
61 || (character >= 0x203f && character <= 0x2040);
77 :
name (nameStart, nameEnd)
155 bool isLegalXmlCharSlow (
const water_uchar character)
noexcept
157 if ((character >=
'a' && character <=
'z')
158 || (character >=
'A' && character <=
'Z')
159 || (character >=
'0' && character <=
'9'))
162 const char*
t =
" .,;:-()_+=?!'#@[]/\\*%~{}$|";
174 void generateLegalCharLookupTable()
177 for (
int i = 0;
i < 256; ++
i)
178 if (isLegalXmlCharSlow (
i))
179 n[
i >> 3] |= (1 << (
i & 7));
182 for (
int i = 0;
i < 32; ++
i)
183 s << (
int)
n[
i] <<
", ";
191 static const unsigned char legalChars[] = { 0, 0, 0, 0, 187, 255, 255, 175, 255,
192 255, 255, 191, 254, 255, 255, 127 };
193 return c <
sizeof (legalChars) * 8
194 && (legalChars [
c >> 3] & (1 << (
c & 7))) != 0;
210 outputStream << (char) character;
216 case '&': outputStream <<
"&";
break;
217 case '"': outputStream <<
""";
break;
218 case '>': outputStream <<
">";
break;
219 case '<': outputStream <<
"<";
break;
223 if (! changeNewLines)
225 outputStream << (char) character;
230 outputStream <<
"&#" << ((
int) character) <<
';';
239 out.writeRepeatedByte (
' ', numSpaces);
244 const int indentationLevel,
245 const int lineWrapLength)
const
251 if (indentationLevel >= 0)
252 writeSpaces (outputStream, (
size_t) indentationLevel);
260 const size_t attIndent = (size_t) (indentationLevel +
tagName.length() + 1);
265 if (lineLen > lineWrapLength && indentationLevel >= 0)
267 outputStream << newLine;
268 writeSpaces (outputStream, attIndent);
274 outputStream << att->name;
275 outputStream.
write (
"=\"", 2);
276 escapeIllegalXmlChars (outputStream, att->value,
true);
286 bool lastWasTextNode =
false;
290 if (child->isTextElement())
292 escapeIllegalXmlChars (outputStream, child->getText(),
false);
293 lastWasTextNode =
true;
297 if (indentationLevel >= 0 && ! lastWasTextNode)
298 outputStream << newLine;
300 child->writeElementAsText (outputStream,
301 lastWasTextNode ? 0 : (indentationLevel + (indentationLevel >= 0 ? 2 : 0)), lineWrapLength);
302 lastWasTextNode =
false;
306 if (indentationLevel >= 0 && ! lastWasTextNode)
308 outputStream << newLine;
309 writeSpaces (outputStream, (
size_t) indentationLevel);
312 outputStream.
write (
"</", 2);
318 outputStream.
write (
"/>", 2);
323 escapeIllegalXmlChars (outputStream,
getText(),
false);
328 const bool allOnOneLine,
329 const bool includeXmlHeader,
331 const int lineWrapLength)
const
334 writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
341 const bool allOnOneLine,
342 const bool includeXmlHeader,
344 const int lineWrapLength)
const
350 if (includeXmlHeader)
352 output <<
"<?xml version=\"1.0\" encoding=\"" << encodingType <<
"\"?>";
357 output << newLine << newLine;
377bool XmlElement::writeToFile (
const File&
file,
380 const int lineWrapLength)
const
387 if (!
out.openedOk())
394 if (
out.getStatus().failed())
398 return tempFile.overwriteTargetFileWithTemporary();
405 const bool matches =
tagName.equalsIgnoreCase (possibleTagName);
416 return tagName.upToFirstOccurrenceOf (
":",
false,
false);
421 return tagName.fromLastOccurrenceOf (
":",
false,
false);
433 while (
e !=
nullptr && !
e->hasTagName (requiredTagName))
453 static std::string empty;
460 return att->name.toString();
476 if (att->name == attributeName)
501 return defaultReturnValue;
509 return defaultReturnValue;
515 return att->value.getDoubleValue();
517 return defaultReturnValue;
524 const water_uchar firstChar = *(att->value.getCharPointer().findEndOfWhitespace());
526 return firstChar ==
'1'
533 return defaultReturnValue;
538 const bool ignoreCase)
const noexcept
541 return ignoreCase ? att->value.equalsIgnoreCase (stringToCompareAgainst)
542 : att->value == stringToCompareAgainst;
558 if (att->name == attributeName)
564 if (att->nextListItem ==
nullptr)
586 att->get() !=
nullptr;
589 if (att->get()->name == attributeName)
591 delete att->removeNext();
615 wassert (! childName.isEmpty());
618 if (child->hasTagName (childName))
626 wassert (! attributeName.isEmpty());
629 if (child->compareAttribute (attributeName, attributeValue))
637 if (newNode !=
nullptr)
640 wassert (newNode->nextListItem ==
nullptr);
648 if (newNode !=
nullptr)
651 wassert (newNode->nextListItem ==
nullptr);
659 if (newNode !=
nullptr)
662 wassert (newNode->nextListItem ==
nullptr);
678 if (newNode !=
nullptr)
682 if (currentChildElement != newNode)
683 delete p->replaceNext (newNode);
693 const bool shouldDeleteTheChild)
noexcept
695 if (childToRemove !=
nullptr)
699 if (shouldDeleteTheChild)
700 delete childToRemove;
705 const bool ignoreOrderOfAttributes)
const noexcept
709 if (other ==
nullptr ||
tagName != other->tagName)
712 if (ignoreOrderOfAttributes)
718 if (! other->compareAttribute (att->name, att->value))
724 if (totalAtts != other->getNumAttributes())
734 if (thisAtt ==
nullptr || otherAtt ==
nullptr)
736 if (thisAtt == otherAtt)
754 const XmlElement* otherChild = other->firstChildElement;
758 if (thisChild ==
nullptr || otherChild ==
nullptr)
760 if (thisChild == otherChild)
766 if (! thisChild->
isEquivalentTo (otherChild, ignoreOrderOfAttributes))
786 XmlElement*
const nextChild = child->nextListItem;
788 if (child->hasTagName (
name))
802 if (
this == elementToLookFor || elementToLookFor ==
nullptr)
807 if (elementToLookFor == child)
810 if (
XmlElement*
const found = child->findParentElementOf (elementToLookFor))
826 for (
int i = 1;
i < num; ++
i)
828 e->nextListItem = elems[
i];
832 e->nextListItem =
nullptr;
869 mem << child->getAllSubText();
877 return child->getAllSubText();
879 return defaultReturnValue;
915 if (child->isTextElement())
#define CARLA_SAFE_ASSERT_RETURN(cond, ret)
Definition CarlaDefines.h:190
#define noexcept
Definition DistrhoDefines.h:72
Definition CharPointer_UTF8.h:45
Definition FileOutputStream.h:42
Definition Identifier.h:44
Definition LinkedListPointer.h:62
Definition MemoryOutputStream.h:42
String toUTF8() const
Definition MemoryOutputStream.cpp:183
Definition OutputStream.h:44
virtual bool write(const void *dataToWrite, size_t numberOfBytes)=0
virtual int64 getPosition()=0
virtual bool writeByte(char byte)
Definition OutputStream.cpp:51
int getIntValue() const noexcept
Definition String.cpp:1781
Definition StringRef.h:67
bool isNotEmpty() const noexcept
Definition StringRef.h:101
Definition TemporaryFile.h:73
const std::string & getAttributeName(int attributeIndex) const noexcept
Definition XmlElement.cpp:457
void copyChildrenAndAttributesFrom(const XmlElement &)
Definition XmlElement.cpp:136
XmlElement * getChildByName(StringRef tagNameToLookFor) const noexcept
Definition XmlElement.cpp:613
LinkedListPointer< XmlElement > nextListItem
Definition XmlElement.h:713
XmlElement * getChildElement(int index) const noexcept
Definition XmlElement.cpp:608
bool hasTagName(StringRef possibleTagName) const noexcept
Definition XmlElement.cpp:403
bool compareAttribute(StringRef attributeName, StringRef stringToCompareAgainst, bool ignoreCase=false) const noexcept
Definition XmlElement.cpp:536
XmlElement * createNewChildElement(StringRef tagName)
Definition XmlElement.cpp:668
XmlElement * getChildByAttribute(StringRef attributeName, StringRef attributeValue) const noexcept
Definition XmlElement.cpp:624
bool hasAttribute(StringRef attributeName) const noexcept
Definition XmlElement.cpp:482
void addChildElement(XmlElement *newChildElement) noexcept
Definition XmlElement.cpp:635
String createDocument(StringRef dtdToUse, bool allOnOneLine=false, bool includeXmlHeader=true, StringRef encodingType="UTF-8", int lineWrapLength=60) const
Definition XmlElement.cpp:327
void deleteAllTextElements() noexcept
Definition XmlElement.cpp:909
void setText(const String &newText)
Definition XmlElement.cpp:852
bool replaceChildElement(XmlElement *currentChildElement, XmlElement *newChildNode) noexcept
Definition XmlElement.cpp:675
void prependChildElement(XmlElement *newChildElement) noexcept
Definition XmlElement.cpp:657
void deleteAllChildElementsWithTagName(StringRef tagName) noexcept
Definition XmlElement.cpp:782
int getIntAttribute(StringRef attributeName, int defaultReturnValue=0) const
Definition XmlElement.cpp:504
void writeElementAsText(OutputStream &, int indentationLevel, int lineWrapLength) const
Definition XmlElement.cpp:243
XmlElement(const String &tagName)
Definition XmlElement.cpp:83
double getDoubleAttribute(StringRef attributeName, double defaultReturnValue=0.0) const
Definition XmlElement.cpp:512
XmlElement * getNextElementWithTagName(StringRef requiredTagName) const
Definition XmlElement.cpp:429
LinkedListPointer< XmlElement > firstChildElement
Definition XmlElement.h:714
int getNumChildElements() const noexcept
Definition XmlElement.cpp:603
LinkedListPointer< XmlAttributeNode > attributes
Definition XmlElement.h:715
const String & getStringAttribute(StringRef attributeName) const noexcept
Definition XmlElement.cpp:488
String getAllSubText() const
Definition XmlElement.cpp:858
void removeChildElement(XmlElement *childToRemove, bool shouldDeleteTheChild) noexcept
Definition XmlElement.cpp:692
bool isTextElement() const noexcept
Definition XmlElement.cpp:836
String tagName
Definition XmlElement.h:716
bool isEquivalentTo(const XmlElement *other, bool ignoreOrderOfAttributes) const noexcept
Definition XmlElement.cpp:704
void getChildElementsAsArray(XmlElement **) const noexcept
Definition XmlElement.cpp:817
String getChildElementAllSubText(StringRef childTagName, const String &defaultReturnValue) const
Definition XmlElement.cpp:874
void removeAttribute(const Identifier &attributeName) noexcept
Definition XmlElement.cpp:583
bool hasTagNameIgnoringNamespace(StringRef possibleTagName) const
Definition XmlElement.cpp:424
void reorderChildElements(XmlElement **, int) noexcept
Definition XmlElement.cpp:822
void insertChildElement(XmlElement *newChildElement, int indexToInsertAt) noexcept
Definition XmlElement.cpp:646
XmlAttributeNode * getAttribute(StringRef) const noexcept
Definition XmlElement.cpp:473
const String & getAttributeValue(int attributeIndex) const noexcept
Definition XmlElement.cpp:465
XmlElement & operator=(const XmlElement &)
Definition XmlElement.cpp:123
int getNumAttributes() const noexcept
Definition XmlElement.cpp:440
static XmlElement * createTextElement(const String &text)
Definition XmlElement.cpp:882
void addTextElement(const String &text)
Definition XmlElement.cpp:904
String getTagNameWithoutNamespace() const
Definition XmlElement.cpp:419
void writeToStream(OutputStream &output, StringRef dtdToUse, bool allOnOneLine=false, bool includeXmlHeader=true, StringRef encodingType="UTF-8", int lineWrapLength=60) const
Definition XmlElement.cpp:339
const String & getText() const noexcept
Definition XmlElement.cpp:843
static bool isValidXmlName(StringRef possibleName) noexcept
Definition XmlElement.cpp:889
~XmlElement() noexcept
Definition XmlElement.cpp:145
void setAttribute(const Identifier &attributeName, const String &newValue)
Definition XmlElement.cpp:548
bool getBoolAttribute(StringRef attributeName, bool defaultReturnValue=false) const
Definition XmlElement.cpp:520
void removeAllAttributes() noexcept
Definition XmlElement.cpp:597
String getNamespace() const
Definition XmlElement.cpp:414
bool containsChildElement(const XmlElement *possibleChild) const noexcept
Definition XmlElement.cpp:795
XmlElement * findParentElementOf(const XmlElement *childToSearchFor) noexcept
Definition XmlElement.cpp:800
void deleteAllChildElements() noexcept
Definition XmlElement.cpp:777
* e
Definition inflate.c:1404
struct huft * t
Definition inflate.c:943
unsigned v[N_MAX]
Definition inflate.c:1584
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
static PuglViewHint int value
Definition pugl.h:1708
static const char * name
Definition pugl.h:1582
#define wassert(expression)
float out
Definition lilv_test.c:1461
Definition XmlElement.cpp:153
static void escapeIllegalXmlChars(OutputStream &outputStream, const String &text, const bool changeNewLines)
Definition XmlElement.cpp:197
static void writeSpaces(OutputStream &out, const size_t numSpaces)
Definition XmlElement.cpp:237
static bool isLegalXmlChar(const uint32 c) noexcept
Definition XmlElement.cpp:189
Definition AudioSampleBuffer.h:33
bool isValidXmlNameBodyCharacter(const water_uchar character) noexcept
Definition XmlElement.cpp:53
unsigned int uint32
Definition water.h:98
static const char *const water_xmltextContentAttributeName
Definition XmlElement.cpp:841
static const std::string & getEmptyStdStringRef() noexcept
Definition XmlElement.cpp:451
bool isValidXmlNameStartCharacter(const water_uchar character) noexcept
Definition XmlElement.cpp:33
static const String & getEmptyStringRef() noexcept
Definition XmlElement.cpp:445
long long int64
Definition water.h:100
unsigned char uint8
Definition water.h:90
uint32 water_uchar
Definition CharacterFunctions.h:38
Definition XmlElement.h:694
Identifier name
Definition XmlElement.h:700
LinkedListPointer< XmlAttributeNode > nextListItem
Definition XmlElement.h:699
XmlAttributeNode(const XmlAttributeNode &) noexcept
Definition XmlElement.cpp:64
String value
Definition XmlElement.h:701
const char * text
Definition swell-functions.h:167
int n
Definition crypt.c:458
uch * p
Definition crypt.c:594
return c
Definition crypt.c:175
typedef int(UZ_EXP MsgFn)()
struct zdirent * file
Definition win32.c:1500
#define const
Definition zconf.h:137