From 4a966ec4fd2e899e9494e87905e90dfbbd97635c Mon Sep 17 00:00:00 2001 From: N2614 Date: Tue, 17 Jan 2012 08:28:25 +0000 Subject: [PATCH] =?UTF-8?q?BGS=E3=81=A8=E3=81=AE=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=E7=B5=90=E6=9E=9C=E3=82=92simplexml=E3=83=A9=E3=82=A4=E3=83=96?= =?UTF-8?q?=E3=83=A9=E3=83=AA=E3=81=A7=E3=83=91=E3=83=BC=E3=82=B9=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=81=9F=E3=82=81=E3=81=AE=E6=AD=A3=E8=A6=8F=E5=8C=96?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@562 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../sources/ConsoleRestore/OMakefile | 1 + .../ConsoleRestore/SimpleXmlPreprocessor.cpp | 176 ++++++++++++++++++ .../ConsoleRestore/SimpleXmlPreprocessor.h | 52 ++++++ 3 files changed, 229 insertions(+) create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.cpp create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.h diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile b/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile index edb5158..998ed67 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile @@ -31,6 +31,7 @@ SOURCES[] = TitleDownloader.cpp Shop.cpp RegionIdModifier.cpp + SimpleXmlPreprocessor.cpp ../common/Util.cpp ../common/DrawSystemState.cpp ../common/FileTransfer.cpp diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.cpp b/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.cpp new file mode 100644 index 0000000..cde1130 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.cpp @@ -0,0 +1,176 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: SimpleXmlPreprocessor.cpp + + Copyright 2009-2011 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#include "SimpleXmlPreprocessor.h" +#include + +namespace ConsoleRestore +{ + +bool SimpleXmlPreprocessor::Canonicalize(std::string& str) +{ + if(!EraseXmlDeclaration(str)) + { + NN_LOG("invalid xml!\n"); + return false; + } + + if(!EraseEmptyTag(str)) + { + NN_LOG("can't erase empty tag"); + return false; + } + + if(!EraseAttribute(str)) + { + NN_LOG("can't erase attribute\n"); + return false; + } + + if(!EraseNsTagEnd(str)) + { + NN_LOG("can't erase ns end\n"); + return false; + } + + if(!EraseNsTagStart(str)) + { + NN_LOG("can't erase ns start\n"); + return false; + } + + return true; +} + +bool SimpleXmlPreprocessor::EraseXmlDeclaration(std::string& str) +{ + std::string::size_type start = str.find(""); + if (end == std::string::npos) + { + return false; + } + + str.erase(start, end + 1 - start); + + return true; +} + +bool SimpleXmlPreprocessor::EraseEmptyTag(std::string& str) +{ + // XMLとしては正しい前提 + std::string::size_type end = str.find("/>"); + if (end == std::string::npos) + { + return true; + } + + std::string::size_type start = str.rfind("<", end); + if (start == std::string::npos) + { + return false; + } + + str.erase(start, end + 2 - start); + + return true; +} + +bool SimpleXmlPreprocessor::EraseNsTagEnd(std::string& str) +{ + std::string::size_type start = str.rfind("", start); + if (end == std::string::npos) + { + // 不正なXML + return false; + } + + std::string::size_type colon = str.substr(start, end - start).find(":"); + if (colon == std::string::npos) + { + // 名前空間無し + start = str.rfind("", start); + if (end == std::string::npos) + { + // 不正なXML + return false; + } + + std::string::size_type colon = str.substr(start, end - start).find(":"); + if (colon == std::string::npos) + { + // 名前空間無し + start = str.find("<", end); + continue; + } + + str.erase(start + 1, colon); + start = str.find("<", end - colon); + } + + return true; +} + +bool SimpleXmlPreprocessor::EraseAttribute(std::string& str) +{ + std::string::size_type start = str.find("<"); + while (start != std::string::npos) + { + std::string::size_type end = str.find(">", start); + if (end == std::string::npos) + { + // 不正なXML + return false; + } + + std::string::size_type space = str.substr(start, end - start).find(" "); + if (space == std::string::npos) + { + // 属性なし + start = str.find("<", end); + continue; + } + + str.erase(start + space, end - (start + space)); + start = str.find("<", start + space); + } + + return true; +} + +} /* namespace ConsoleRestore */ diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.h b/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.h new file mode 100644 index 0000000..11f2ffa --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.h @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: SimpleXmlPreprocessor.h + + Copyright 2009-2011 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#ifndef SIMPLEXMLPREPROCESSOR_H_ +#define SIMPLEXMLPREPROCESSOR_H_ + +#include + +namespace ConsoleRestore +{ + +class SimpleXmlPreprocessor +{ +public: + SimpleXmlPreprocessor() {}; + ~SimpleXmlPreprocessor() {}; + + // SimpleXmlParserで読めるように変換します + static bool Canonicalize(std::string& str); + +private: + // の除去 + static bool EraseXmlDeclaration(std::string& str); + + // 空タグの除去 + static bool EraseEmptyTag(std::string& str); + + // 属性の削除 + static bool EraseAttribute(std::string& str); + + // 終了タグの名前空間の削除 + static bool EraseNsTagEnd(std::string& str); + + // 開始タグの名前空間の削除 + static bool EraseNsTagStart(std::string& str); + +}; + +} /* namespace ConsoleRestore */ +#endif /* SIMPLEXMLPREPROCESSOR_H_ */