diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index da283f8..a2ac7c5 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 76b3fb1..0000000 --- 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 65a4094..2013dec 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 93ebb98..0000000 --- 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 e61c432..0000000 --- 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, - } -}