From 8d751e14c801ae5ae40c5ae374734fb3c80cba32 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sun, 26 Sep 2021 15:49:24 +0800 Subject: [PATCH 1/3] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/BUILD.gn new file: convertxml/build_ts_js.py modified: convertxml/js_convertxml.cpp modified: convertxml/js_convertxml.h modified: convertxml/js_convertxml.js new file: convertxml/src/js_convertxml.ts new file: convertxml/tsconfig.json --- convertxml/BUILD.gn | 10 ++- convertxml/build_ts_js.py | 21 +++++ convertxml/js_convertxml.cpp | 134 ++++++++++++++++++++++++++++++-- convertxml/js_convertxml.h | 67 +++++++++------- convertxml/js_convertxml.js | 95 +++++++++++++++------- convertxml/src/js_convertxml.ts | 130 +++++++++++++++++++++++++++++++ convertxml/tsconfig.json | 14 ++++ 7 files changed, 408 insertions(+), 63 deletions(-) create mode 100644 convertxml/build_ts_js.py create mode 100644 convertxml/src/js_convertxml.ts create mode 100644 convertxml/tsconfig.json diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index a2ac7c53..da283f8a 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -14,11 +14,19 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +action("build_ts_js") { + script = "//base/compileruntime/js_api_module/convertxml/build_ts_js.py" + depfile = "$target_gen_dir/$target_name.d" + outputs = [target_out_dir + "/js_convertxml.js" + ] +} + base_output_path = get_label_info(":js_convertxml", "target_out_dir") js_xml_obj_path = base_output_path + "/convertxml.o" gen_js_obj("js_convertxml") { - input = "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" + input = "$target_out_dir/js_convertxml.js" output = js_xml_obj_path + dep = ":build_ts_js" } ohos_shared_library("convertxml") { diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py new file mode 100644 index 00000000..76b3fb1d --- /dev/null +++ b/convertxml/build_ts_js.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os + +if __name__ == '__main__': + + build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) + os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 2261268a..65a40944 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -283,18 +283,23 @@ void ConvertXml::SetSpacesInfo(napi_value &object) napi_value ConvertXml::convert(std::string strXml) { - xmlDocPtr doc = NULL; - xmlNodePtr curNode = NULL; + xmlDocPtr doc = nullptr; + xmlNodePtr curNode = nullptr; napi_status status = napi_ok; napi_value object = nullptr; status = napi_create_object(env_, &object); if (status != napi_ok) { - return NULL; + return nullptr; } + Replace(strXml, "\\r", "\r"); + Replace(strXml, "\\n", "\n"); + Replace(strXml, "\\v", "\v"); + Replace(strXml, "]]> encoding != nullptr) { SetKeyValue(subSubObject, "encoding", (const char*)doc->encoding); } - if (!m_Options.ignoreDeclaration && strXml.find("xml") != std::string::npos) { napi_set_named_property(env_, subObject, m_Options.attributes.c_str(), subSubObject); napi_set_named_property(env_, object, m_Options.declaration.c_str(), subObject); } - curNode = xmlDocGetRootElement(doc); - GetPrevNodeList(curNode); - GetXMLInfo(curNode, object, 0); + if (doc != nullptr) { + curNode = xmlDocGetRootElement(doc); + GetPrevNodeList(curNode); + GetXMLInfo(curNode, object, 0); + } SetSpacesInfo(object); return object; } @@ -459,4 +465,118 @@ void ConvertXml::DealOptions(napi_value napi_obj) } DealIgnore(napi_obj); DealSpaces(napi_obj); +} + +void ConvertXml::DealSingleLine(std::string &strXml, napi_value &object) +{ + size_t iXml = 0; + if ((iXml = strXml.find("xml")) != std::string::npos) { + m_XmlInfo.bXml = true; + napi_value declObj = nullptr; + napi_create_object(env_, &declObj); + napi_value attrObj = nullptr; + bool bFlag = false; + napi_create_object(env_, &attrObj); + if (strXml.find("version=") != std::string::npos) { + m_XmlInfo.bVersion = true; + SetKeyValue(attrObj, "version", "1.0"); + bFlag = true; + } + if (strXml.find("encoding=") != std::string::npos) { + m_XmlInfo.bEncoding = false; + SetKeyValue(attrObj, "encoding", "utf-8"); + bFlag = true; + } + if (bFlag) { + napi_set_named_property(env_, declObj, m_Options.attributes.c_str(), attrObj); + napi_set_named_property(env_, object, m_Options.declaration.c_str(), declObj); + } else { + napi_set_named_property(env_, object, m_Options.declaration.c_str(), declObj); + } + if (strXml.find(">", iXml) == strXml.size() - 1) { + strXml = ""; + } else { + strXml = strXml.substr(0, strXml.rfind("<", iXml)) + strXml.substr(strXml.find(">", iXml) + 1); + } + } + size_t iCount = 0; + size_t iLen = strXml.size(); + for (; iCount < iLen; ++iCount) { + if (strXml[iCount] != ' ' && strXml[iCount] != '\v' && + strXml[iCount] != '\t' && strXml[iCount] != '\n') { + break; + } + } + if (iCount < iLen) { + DealComplex(strXml, object); + } +} + +void ConvertXml::DealComplex(std::string &strXml, napi_value &object) +{ + if (strXml.find(""; + } else { + strXml = "" + strXml + ""; + } + xmlDocPtr doc = nullptr; + xmlNodePtr curNode = nullptr; + size_t len = strXml.size(); + doc = xmlParseMemory(strXml.c_str(), len); + if (!doc) { + xmlFreeDoc(doc); + } + if (doc) { + curNode = xmlDocGetRootElement(doc); + curNode = curNode->children; + napi_value elements = nullptr; + napi_create_array(env_, &elements); + bool bHasEle = false; + int index = 0; + bool bCData = false; + if (strXml.find("type == xmlElementType::XML_CDATA_SECTION_NODE && + curNode->next && curNode->next->type == xmlElementType::XML_TEXT_NODE && + curNode->next->next && curNode->next->next->type == xmlElementType::XML_CDATA_SECTION_NODE) { + if (xmlNodeGetContent(curNode->next) != nullptr) { + std::string strTemp = (char*)xmlNodeGetContent(curNode->next); + Replace(strTemp, " ", ""); + Replace(strTemp, "\v", ""); + Replace(strTemp, "\t", ""); + Replace(strTemp, "\n", ""); + if (strTemp == "") { + curNode = curNode->next->next; + } + } + } else { + curNode = curNode->next; + } } \ No newline at end of file diff --git a/convertxml/js_convertxml.h b/convertxml/js_convertxml.h index a44b731c..380fab06 100755 --- a/convertxml/js_convertxml.h +++ b/convertxml/js_convertxml.h @@ -30,33 +30,41 @@ enum class SpaceType { }; struct Options { - std::string declaration = "_declaration"; - std::string instruction = "_instruction"; - std::string attributes = "_attributes"; - std::string text = "_text"; - std::string cdata = "_cdata"; - std::string doctype = "_doctype"; - std::string comment = "_comment"; - std::string parent = "_parent"; - std::string type = "_type"; - std::string name = "_name"; - std::string elements = "_elements"; - bool compact = false; - bool trim = false; - bool nativetype = false; - bool nativetypeattributes = false; - bool addparent = false; - bool alwaysArray = false; - bool alwaysChildren = false; - bool instructionHasAttributes = false; - bool ignoreDeclaration = false; - bool ignoreInstruction = false; - bool ignoreAttributes = false; - bool ignoreComment = false; - bool ignoreCdata = false; - bool ignoreDoctype = false; - bool ignoreText = false; - bool spaces = false; + std::string declaration = "_declaration"; + std::string instruction = "_instruction"; + std::string attributes = "_attributes"; + std::string text = "_text"; + std::string cdata = "_cdata"; + std::string doctype = "_doctype"; + std::string comment = "_comment"; + std::string parent = "_parent"; + std::string type = "_type"; + std::string name = "_name"; + std::string elements = "_elements"; + bool compact = false; + bool trim = false; + bool nativetype = false; + bool nativetypeattributes = false; + bool addparent = false; + bool alwaysArray = false; + bool alwaysChildren = false; + bool instructionHasAttributes = false; + bool ignoreDeclaration = false; + bool ignoreInstruction = false; + bool ignoreAttributes = false; + bool ignoreComment = false; + bool ignoreCdata = false; + bool ignoreDoctype = false; + bool ignoreText = false; + bool spaces = false; +}; + +struct XmlInfo { + bool bXml = false; + bool bVersion = false; + std::string strVersion = ""; + bool bEncoding = false; + std::string strEncoding = ""; }; class ConvertXml { @@ -80,6 +88,10 @@ public: void SetPrevInfo(napi_value &recvElement, int flag, int32_t &index1); void SetDefaultKey(size_t i, std::string strRecv); void SetSpacesInfo(napi_value &object); + void DealSingleLine(std::string &strXml, napi_value &object); + void DealComplex(std::string &strXml, napi_value &object); + void Replace(std::string &str, const std::string src, const std::string dst); + void DealCDataInfo(bool bCData, xmlNodePtr &curNode); private: napi_env env_; SpaceType m_SpaceType; @@ -87,5 +99,6 @@ private: std::string m_strSpace; Options m_Options; std::vector m_prevObj; + XmlInfo m_XmlInfo; }; #endif \ No newline at end of file diff --git a/convertxml/js_convertxml.js b/convertxml/js_convertxml.js index 3b6b5ba2..e045ea7a 100755 --- a/convertxml/js_convertxml.js +++ b/convertxml/js_convertxml.js @@ -28,32 +28,81 @@ class ConvertXml { space = converted.spaces; delete converted.spaces; } - return JSON.stringify(converted, null, space); + var strEnd = JSON.stringify(converted, null, space); + var idx = 0; + while ((idx = strEnd.indexOf('\\t')) != -1) { + strEnd = strEnd.substring(0, idx) + '\t' + strEnd.substring(idx + 2); + } + while ((idx = strEnd.indexOf('\\n')) != -1) { + strEnd = strEnd.substring(0, idx) + '\n' + strEnd.substring(idx + 2); + } + while ((idx = strEnd.indexOf('\\')) != -1) { + strEnd = strEnd.substring(0, idx) + '' + strEnd.substring(idx + 1); + } + return strEnd; } } function DealXml(strXml) { - var idx = -1; + var idx = 0; var idxSec = 0; var idxThir = 0; var idxCData = 0; var idxCDataSec = 0; + while ((idx = strXml.indexOf(']]>', idxSec)) != -1) { idxThir = strXml.indexOf('<', idx); - var i = idx + 1; - for (; i < idxThir ; i++) { - var cXml = strXml.charAt(i); - if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') - { - break; + strXml = DealReplace(strXml, idx, idxThir); + if (strXml.indexOf('<', idx) != -1) { + idxCData = strXml.indexOf('', idxCData); + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i) + switch (cXml) { + case '\n': + strXml = strXml.substring(0, i) + '\\n' + strXml.substring(i + 1); + break; + case '\v': + strXml = strXml.substring(0, i) + '\\v' + strXml.substring(i + 1); + break; + case '\t': + strXml = strXml.substring(0, i) + '\\t' + strXml.substring(i + 1); + break; + default: + break; + } + } + idxCDataSec = idxSec; } } - var j = idx + 1; - for (; j < strXml.indexOf('<', idx) ; j++) { - var cXml = strXml.charAt(j); - if (i != idxThir) { - switch (cXml) { + else { + break; + } + } + return strXml; +} + +function DealReplace(strXml, idx, idxThir) +{ + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i); + if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') + { + break; + } + } + var j = idx + 1; + for (; j < strXml.indexOf('<', idx) ; j++) { + var cXml = strXml.charAt(j); + if (i != idxThir) { + switch (cXml) { case '\n': strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); break; @@ -63,22 +112,12 @@ function DealXml(strXml) case '\t': strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); break; - } - } else { - strXml = strXml.substring(0, j) + strXml.substring(j + 1); - --j; - } - } - if (strXml.indexOf('<', idx) != -1) { - idxCData = strXml.indexOf('', idxSec)) != -1) { + idxThir = strXml.indexOf('<', idx); + strXml = DealReplace(strXml, idx, idxThir); + if (strXml.indexOf('<', idx) != -1) { + idxCData = strXml.indexOf('', idxCData); + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i) + switch (cXml) { + case '\n': + strXml = strXml.substring(0, i) + '\\n' + strXml.substring(i + 1); + break; + case '\v': + strXml = strXml.substring(0, i) + '\\v' + strXml.substring(i + 1); + break; + case '\t': + strXml = strXml.substring(0, i) + '\\t' + strXml.substring(i + 1); + break; + default: + break; + } + } + idxCDataSec = idxSec; + } + } + else { + break; + } + } + return strXml; +} + +function DealReplace(strXml : string, idx : any, idxThir : any) +{ + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i); + if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') + { + break; + } + } + var j = idx + 1; + for (; j < strXml.indexOf('<', idx) ; j++) { + var cXml = strXml.charAt(j); + if (i != idxThir) { + switch (cXml) { + case '\n': + strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); + break; + case '\v': + strXml = strXml.substring(0, j) + '\\v' + strXml.substring(j + 1); + break; + case '\t': + strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); + break; + default: + break; + } + } else { + strXml = strXml.substring(0, j) + strXml.substring(j + 1); + --j; + } + } + return strXml; +} + +export default { + ConvertXml : ConvertXml +} + + diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json new file mode 100644 index 00000000..e61c432f --- /dev/null +++ b/convertxml/tsconfig.json @@ -0,0 +1,14 @@ +{ +"compilerOptions": { + "target": "es6", + "module": "es6", + "rootDir": "./src", + //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "noImplicitThis": false, + } +} -- Gitee From 4079228e11559bef430c4a320175dcea41dbefd8 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sun, 26 Sep 2021 16:10:16 +0800 Subject: [PATCH 2/3] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/BUILD.gn deleted: convertxml/build_ts_js.py modified: convertxml/js_convertxml.cpp deleted: convertxml/src/js_convertxml.ts deleted: convertxml/tsconfig.json --- convertxml/BUILD.gn | 10 +-- convertxml/build_ts_js.py | 21 ------ convertxml/js_convertxml.cpp | 16 ++-- convertxml/src/js_convertxml.ts | 130 -------------------------------- convertxml/tsconfig.json | 14 ---- 5 files changed, 10 insertions(+), 181 deletions(-) delete mode 100644 convertxml/build_ts_js.py delete mode 100644 convertxml/src/js_convertxml.ts delete mode 100644 convertxml/tsconfig.json diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index da283f8a..a2ac7c53 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -14,19 +14,11 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") -action("build_ts_js") { - script = "//base/compileruntime/js_api_module/convertxml/build_ts_js.py" - depfile = "$target_gen_dir/$target_name.d" - outputs = [target_out_dir + "/js_convertxml.js" - ] -} - base_output_path = get_label_info(":js_convertxml", "target_out_dir") js_xml_obj_path = base_output_path + "/convertxml.o" gen_js_obj("js_convertxml") { - input = "$target_out_dir/js_convertxml.js" + input = "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" output = js_xml_obj_path - dep = ":build_ts_js" } ohos_shared_library("convertxml") { diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py deleted file mode 100644 index 76b3fb1d..00000000 --- a/convertxml/build_ts_js.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os - -if __name__ == '__main__': - - build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) - os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) - os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 65a40944..2013decb 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -86,7 +86,7 @@ std::string ConvertXml::Trim(std::string strXmltrim) } size_t i = 0; size_t strlen = strXmltrim.size(); - for (; i < strlen;) { + for (; i < strlen; ) { if (strXmltrim[i] == ' ') { i++; } else { @@ -467,7 +467,7 @@ void ConvertXml::DealOptions(napi_value napi_obj) DealSpaces(napi_obj); } -void ConvertXml::DealSingleLine(std::string &strXml, napi_value &object) +void ConvertXml::DealSingleLine(std::string &strXml,napi_value &object) { size_t iXml = 0; if ((iXml = strXml.find("xml")) != std::string::npos) { @@ -499,6 +499,7 @@ void ConvertXml::DealSingleLine(std::string &strXml, napi_value &object) strXml = strXml.substr(0, strXml.rfind("<", iXml)) + strXml.substr(strXml.find(">", iXml) + 1); } } + size_t iCount = 0; size_t iLen = strXml.size(); for (; iCount < iLen; ++iCount) { @@ -568,11 +569,12 @@ void ConvertXml::DealCDataInfo(bool bCData, xmlNodePtr &curNode) curNode->next->next && curNode->next->next->type == xmlElementType::XML_CDATA_SECTION_NODE) { if (xmlNodeGetContent(curNode->next) != nullptr) { std::string strTemp = (char*)xmlNodeGetContent(curNode->next); - Replace(strTemp, " ", ""); - Replace(strTemp, "\v", ""); - Replace(strTemp, "\t", ""); - Replace(strTemp, "\n", ""); - if (strTemp == "") { + Replace(strTemp, " ",""); + Replace(strTemp, "\v",""); + Replace(strTemp, "\t",""); + Replace(strTemp, "\n",""); + if (strTemp == "") + { curNode = curNode->next->next; } } diff --git a/convertxml/src/js_convertxml.ts b/convertxml/src/js_convertxml.ts deleted file mode 100644 index 93ebb980..00000000 --- a/convertxml/src/js_convertxml.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -declare function requireInternal(s : string) : any; -const convertXml = requireInternal("ConvertXML"); -class ConvertXml { - convertxmlclass; - constructor() { - this.convertxmlclass = new convertXml.ConvertXml(); - } - convert(strXml : string, options : any) { - strXml = DealXml(strXml); - let converted = this.convertxmlclass.convert(strXml, options); - let space = 0; - if (converted.hasOwnProperty("spaces")) { - space = converted.spaces; - delete converted.spaces; - } - var strEnd = JSON.stringify(converted, null, space); - var idx = 0; - while ((idx = strEnd.indexOf('\\t')) != -1) { - strEnd = strEnd.substring(0, idx) + '\t' + strEnd.substring(idx + 2); - } - while ((idx = strEnd.indexOf('\\n')) != -1) { - strEnd = strEnd.substring(0, idx) + '\n' + strEnd.substring(idx + 2); - } - while ((idx = strEnd.indexOf('\\')) != -1) { - strEnd = strEnd.substring(0, idx) + '' + strEnd.substring(idx + 1); - } - return strEnd; - } -} - -function DealXml(strXml : string) -{ - var idx = 0; - var idxSec = 0; - var idxThir = 0; - var idxCData = 0; - var idxCDataSec = 0; - while ((idx = strXml.indexOf(']]>', idxSec)) != -1) { - idxThir = strXml.indexOf('<', idx); - strXml = DealReplace(strXml, idx, idxThir); - if (strXml.indexOf('<', idx) != -1) { - idxCData = strXml.indexOf('', idxCData); - var i = idx + 1; - for (; i < idxThir ; i++) { - var cXml = strXml.charAt(i) - switch (cXml) { - case '\n': - strXml = strXml.substring(0, i) + '\\n' + strXml.substring(i + 1); - break; - case '\v': - strXml = strXml.substring(0, i) + '\\v' + strXml.substring(i + 1); - break; - case '\t': - strXml = strXml.substring(0, i) + '\\t' + strXml.substring(i + 1); - break; - default: - break; - } - } - idxCDataSec = idxSec; - } - } - else { - break; - } - } - return strXml; -} - -function DealReplace(strXml : string, idx : any, idxThir : any) -{ - var i = idx + 1; - for (; i < idxThir ; i++) { - var cXml = strXml.charAt(i); - if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') - { - break; - } - } - var j = idx + 1; - for (; j < strXml.indexOf('<', idx) ; j++) { - var cXml = strXml.charAt(j); - if (i != idxThir) { - switch (cXml) { - case '\n': - strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); - break; - case '\v': - strXml = strXml.substring(0, j) + '\\v' + strXml.substring(j + 1); - break; - case '\t': - strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); - break; - default: - break; - } - } else { - strXml = strXml.substring(0, j) + strXml.substring(j + 1); - --j; - } - } - return strXml; -} - -export default { - ConvertXml : ConvertXml -} - - diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json deleted file mode 100644 index e61c432f..00000000 --- a/convertxml/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ -"compilerOptions": { - "target": "es6", - "module": "es6", - "rootDir": "./src", - //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true, - "noImplicitThis": false, - } -} -- Gitee From e2baadf8d278041261dd905279e2060d0fc48a80 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sun, 26 Sep 2021 16:12:54 +0800 Subject: [PATCH 3/3] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/js_convertxml.cpp --- convertxml/js_convertxml.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 2013decb..65a40944 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -86,7 +86,7 @@ std::string ConvertXml::Trim(std::string strXmltrim) } size_t i = 0; size_t strlen = strXmltrim.size(); - for (; i < strlen; ) { + for (; i < strlen;) { if (strXmltrim[i] == ' ') { i++; } else { @@ -467,7 +467,7 @@ void ConvertXml::DealOptions(napi_value napi_obj) DealSpaces(napi_obj); } -void ConvertXml::DealSingleLine(std::string &strXml,napi_value &object) +void ConvertXml::DealSingleLine(std::string &strXml, napi_value &object) { size_t iXml = 0; if ((iXml = strXml.find("xml")) != std::string::npos) { @@ -499,7 +499,6 @@ void ConvertXml::DealSingleLine(std::string &strXml,napi_value &object) strXml = strXml.substr(0, strXml.rfind("<", iXml)) + strXml.substr(strXml.find(">", iXml) + 1); } } - size_t iCount = 0; size_t iLen = strXml.size(); for (; iCount < iLen; ++iCount) { @@ -569,12 +568,11 @@ void ConvertXml::DealCDataInfo(bool bCData, xmlNodePtr &curNode) curNode->next->next && curNode->next->next->type == xmlElementType::XML_CDATA_SECTION_NODE) { if (xmlNodeGetContent(curNode->next) != nullptr) { std::string strTemp = (char*)xmlNodeGetContent(curNode->next); - Replace(strTemp, " ",""); - Replace(strTemp, "\v",""); - Replace(strTemp, "\t",""); - Replace(strTemp, "\n",""); - if (strTemp == "") - { + Replace(strTemp, " ", ""); + Replace(strTemp, "\v", ""); + Replace(strTemp, "\t", ""); + Replace(strTemp, "\n", ""); + if (strTemp == "") { curNode = curNode->next->next; } } -- Gitee