mirror of
https://github.com/openharmony/js_api_module.git
synced 2026-08-24 22:21:26 -04:00
Signed-off-by: lifansheng <lifansheng1@huawei.com>
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
This commit is contained in:
+1
-9
@@ -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") {
|
||||
|
||||
@@ -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')
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(']]><![CDATA')) != -1) {
|
||||
strXml = strXml.substring(0, idx + 3) + ' ' + strXml.substring(idx + 3);
|
||||
}
|
||||
while ((idx = strXml.indexOf('>', idxSec)) != -1) {
|
||||
idxThir = strXml.indexOf('<', idx);
|
||||
strXml = DealReplace(strXml, idx, idxThir);
|
||||
if (strXml.indexOf('<', idx) != -1) {
|
||||
idxCData = strXml.indexOf('<![CDATA', idxCDataSec);
|
||||
idxSec = strXml.indexOf('<', idx);
|
||||
if (idxSec == idxCData) {
|
||||
idxSec = 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
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user