MCPcopy Create free account
hub / github.com/CyanogenMod/android_frameworks_base / removeWhitespace

Method removeWhitespace

tools/aapt/XMLNode.cpp:874–930  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

872}
873
874void XMLNode::removeWhitespace(bool stripAll, const char** cDataTags)
875{
876 //printf("Removing whitespace in %s\n", String8(mElementName).string());
877 size_t N = mChildren.size();
878 if (cDataTags) {
879 String8 tag(mElementName);
880 const char** p = cDataTags;
881 while (*p) {
882 if (tag == *p) {
883 stripAll = false;
884 break;
885 }
886 }
887 }
888 for (size_t i=0; i<N; i++) {
889 sp<XMLNode> node = mChildren.itemAt(i);
890 if (node->getType() == TYPE_CDATA) {
891 // This is a CDATA node...
892 const char16_t* p = node->mChars.string();
893 while (*p != 0 && *p < 128 && isspace(*p)) {
894 p++;
895 }
896 //printf("Space ends at %d in \"%s\"\n",
897 // (int)(p-node->mChars.string()),
898 // String8(node->mChars).string());
899 if (*p == 0) {
900 if (stripAll) {
901 // Remove this node!
902 mChildren.removeAt(i);
903 N--;
904 i--;
905 } else {
906 node->mChars = String16(" ");
907 }
908 } else {
909 // Compact leading/trailing whitespace.
910 const char16_t* e = node->mChars.string()+node->mChars.size()-1;
911 while (e > p && *e < 128 && isspace(*e)) {
912 e--;
913 }
914 if (p > node->mChars.string()) {
915 p--;
916 }
917 if (e < (node->mChars.string()+node->mChars.size()-1)) {
918 e++;
919 }
920 if (p > node->mChars.string() ||
921 e < (node->mChars.string()+node->mChars.size()-1)) {
922 String16 tmp(p, e-p+1);
923 node->mChars = tmp;
924 }
925 }
926 } else {
927 node->removeWhitespace(stripAll, cDataTags);
928 }
929 }
930}
931

Callers 2

compileXmlFileFunction · 0.80
parseXMLResourceFunction · 0.80

Calls 5

stringMethod · 0.80
String16Class · 0.70
sizeMethod · 0.65
getTypeMethod · 0.65
removeAtMethod · 0.45

Tested by

no test coverage detected