Merge lp:~qqworini/ubuntu-rssreader-app/new-settings-help into lp:ubuntu-rssreader-app

Proposed by Joey Chan
Status: Merged
Approved by: Joey Chan
Approved revision: 422
Merged at revision: 437
Proposed branch: lp:~qqworini/ubuntu-rssreader-app/new-settings-help
Merge into: lp:ubuntu-rssreader-app
Diff against target: 7285 lines (+3809/-1224)
51 files modified
shorts/CMakeLists.txt (+1/-1)
shorts/main.cpp (+1/-1)
shorts/po/com.ubuntu.shorts.pot (+152/-64)
shorts/qml/components/NetworkManager.qml (+2/-2)
shorts/qml/components/OptionsKeeper.qml (+47/-22)
shorts/qml/components/SettingsItem.qml (+120/-0)
shorts/qml/icons/CMakeLists.txt (+1/-1)
shorts/qml/nongoogle/Positioner.qml (+8/-5)
shorts/qml/nongoogle/XmlNetwork.qml (+7/-1)
shorts/qml/pages/PageHelp.qml (+371/-0)
shorts/qml/pages/PageInfo.qml (+79/-0)
shorts/qml/pages/PageSettings.qml (+15/-2)
shorts/qml/shorts-app.qml (+44/-31)
shorts/qml/utils/databasemodule_v2.js (+3/-3)
shorts/qml/utils/xml2json.js (+242/-0)
shorts/shorts.pro (+2/-2)
shorts/shorts.qrc (+8/-0)
shorts/utilities.cpp (+68/-0)
shorts/utilities.h (+28/-0)
shorts/xml2json/rapidjson/allocators.h (+42/-26)
shorts/xml2json/rapidjson/document.h (+256/-95)
shorts/xml2json/rapidjson/encodedstream.h (+38/-58)
shorts/xml2json/rapidjson/encodings.h (+89/-84)
shorts/xml2json/rapidjson/error/en.h (+27/-24)
shorts/xml2json/rapidjson/error/error.h (+29/-24)
shorts/xml2json/rapidjson/filereadstream.h (+24/-19)
shorts/xml2json/rapidjson/filewritestream.h (+27/-20)
shorts/xml2json/rapidjson/internal/biginteger.h (+31/-35)
shorts/xml2json/rapidjson/internal/diyfp.h (+37/-47)
shorts/xml2json/rapidjson/internal/dtoa.h (+29/-37)
shorts/xml2json/rapidjson/internal/ieee754.h (+32/-45)
shorts/xml2json/rapidjson/internal/itoa.h (+21/-23)
shorts/xml2json/rapidjson/internal/meta.h (+14/-22)
shorts/xml2json/rapidjson/internal/pow10.h (+15/-19)
shorts/xml2json/rapidjson/internal/stack.h (+36/-23)
shorts/xml2json/rapidjson/internal/strfunc.h (+15/-19)
shorts/xml2json/rapidjson/internal/strtod.h (+48/-63)
shorts/xml2json/rapidjson/internal/swap.h (+37/-0)
shorts/xml2json/rapidjson/memorybuffer.h (+13/-19)
shorts/xml2json/rapidjson/memorystream.h (+23/-19)
shorts/xml2json/rapidjson/msinttypes/inttypes.h (+4/-0)
shorts/xml2json/rapidjson/msinttypes/stdint.h (+8/-4)
shorts/xml2json/rapidjson/pointer.h (+1326/-0)
shorts/xml2json/rapidjson/prettywriter.h (+21/-25)
shorts/xml2json/rapidjson/rapidjson.h (+88/-32)
shorts/xml2json/rapidjson/reader.h (+195/-119)
shorts/xml2json/rapidjson/stringbuffer.h (+13/-19)
shorts/xml2json/rapidjson/writer.h (+46/-47)
shorts/xml2json/utilities.cpp (+0/-46)
shorts/xml2json/utilities.h (+0/-24)
shorts/xml2json/xml2json.hpp (+26/-52)
To merge this branch: bzr merge lp:~qqworini/ubuntu-rssreader-app/new-settings-help
Reviewer Review Type Date Requested Status
Jenkins Bot continuous-integration Approve
Ubuntu Shorts Developers Pending
Review via email: mp+289180@code.launchpad.net

Commit message

0. replace U1DB with QSettings
1. add a help page
2. add an info page

To all reviewers, in those new added pages, some words, sentences or statements may NOT right or NOT clear, pls help me to correct them before merge :)

Description of the change

0. replace U1DB with QSettings
1. add a help page
2. add an info page

To post a comment you must log in.
Revision history for this message
Roman Shchekin (mrqtros) wrote :

Great work, mate! Give me some time to test it :)

As you may know I am preparing a lot of changes right now, so I foresee a lot of merge conflicts =\

Revision history for this message
Roman Shchekin (mrqtros) wrote :

Seems that *.pro version is broken.

422. By Joey Chan

use qsettings to replace U1DB, and a new help page, a new info page, fix .pro config

Revision history for this message
Roman Shchekin (mrqtros) wrote :

Last question - should you replace "Author" with "Authors"? (Help page)

Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'shorts/CMakeLists.txt'
2--- shorts/CMakeLists.txt 2015-12-02 17:03:41 +0000
3+++ shorts/CMakeLists.txt 2016-03-18 09:56:42 +0000
4@@ -5,7 +5,7 @@
5 main.cpp
6 CachingNetworkManagerFactory.cpp
7 shorts.qrc
8- xml2json/utilities.cpp
9+ utilities.cpp
10
11 )
12
13
14=== modified file 'shorts/main.cpp'
15--- shorts/main.cpp 2015-12-02 17:03:41 +0000
16+++ shorts/main.cpp 2016-03-18 09:56:42 +0000
17@@ -3,7 +3,7 @@
18 #include <QtQuick>
19
20 #include "CachingNetworkManagerFactory.h"
21-#include "xml2json/utilities.h"
22+#include "utilities.h"
23
24 int main(int argc, char *argv[])
25 {
26
27=== modified file 'shorts/po/com.ubuntu.shorts.pot'
28--- shorts/po/com.ubuntu.shorts.pot 2016-03-11 21:32:19 +0000
29+++ shorts/po/com.ubuntu.shorts.pot 2016-03-18 09:56:42 +0000
30@@ -8,7 +8,7 @@
31 msgstr ""
32 "Project-Id-Version: \n"
33 "Report-Msgid-Bugs-To: \n"
34-"POT-Creation-Date: 2016-01-14 22:46+0800\n"
35+"POT-Creation-Date: 2016-03-11 20:54+0800\n"
36 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
37 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
38 "Language-Team: LANGUAGE <LL@li.org>\n"
39@@ -65,8 +65,8 @@
40 msgstr ""
41
42 #: ../qml/nongoogle/AppendNGFeedPage.qml:30 ../qml/pages/AppendFeedPage.qml:31
43-#: ../qml/shorts-app.qml:255 ../qml/shorts-app.qml:390
44-#: ../qml/shorts-app.qml:398
45+#: ../qml/shorts-app.qml:265 ../qml/shorts-app.qml:403
46+#: ../qml/shorts-app.qml:411
47 msgid "Add feeds"
48 msgstr ""
49
50@@ -90,7 +90,7 @@
51
52 #: ../qml/nongoogle/AppendNGFeedPage.qml:197
53 #: ../qml/pages/AppendFeedPage.qml:243 ../qml/pages/CreateTopicPage.qml:38
54-#: ../qml/pages/TopicManagement.qml:239 ../qml/shorts-app.qml:481
55+#: ../qml/pages/TopicManagement.qml:239 ../qml/shorts-app.qml:494
56 msgid "Cancel"
57 msgstr ""
58
59@@ -157,7 +157,6 @@
60
61 #: ../qml/pages/ChooseTopicPage.qml:109 ../qml/pages/ChooseTopicPage.qml:122
62 #: ../qml/pages/CreateTopicPage.qml:66 ../qml/pages/CreateTopicPage.qml:78
63-#: ../qml/shorts-app.qml:568
64 msgid "Warning"
65 msgstr ""
66
67@@ -201,32 +200,159 @@
68 msgid "Topic: "
69 msgstr ""
70
71-#: ../qml/pages/PageSettings.qml:9 ../qml/shorts-app.qml:239
72+#: ../qml/pages/PageHelp.qml:15
73+msgid "Welcome to Shorts"
74+msgstr ""
75+
76+#: ../qml/pages/PageHelp.qml:17
77+msgid "View Articles"
78+msgstr ""
79+
80+#: ../qml/pages/PageHelp.qml:19
81+msgid "Search RSS"
82+msgstr ""
83+
84+#: ../qml/pages/PageHelp.qml:21
85+msgid "Manage topics and feeds"
86+msgstr ""
87+
88+#: ../qml/pages/PageHelp.qml:23
89+msgid "Location"
90+msgstr ""
91+
92+#: ../qml/pages/PageHelp.qml:25
93+msgid "Enjoy"
94+msgstr ""
95+
96+#: ../qml/pages/PageHelp.qml:105
97+msgid "Shorts is an RSS reader app developed by Canonical & Ubuntu Comunity."
98+msgstr ""
99+
100+#: ../qml/pages/PageHelp.qml:110
101+msgid ""
102+"Shorts provides most primary features which also can be seen in other RSS "
103+"reader apps, with a beautiful Ubuntu style user interface."
104+msgstr ""
105+
106+#: ../qml/pages/PageHelp.qml:117
107+msgid "Swipe left to continue."
108+msgstr ""
109+
110+#: ../qml/pages/PageHelp.qml:136
111+msgid "Scroll left/right in grid mode or scroll up/down in list mode."
112+msgstr ""
113+
114+#: ../qml/pages/PageHelp.qml:163
115+msgid ""
116+"Swipe up will enter this search page, just type any simple words, or paste a "
117+"link."
118+msgstr ""
119+
120+#: ../qml/pages/PageHelp.qml:190
121+msgid ""
122+"Every feed must belong to one topic, swipe one item to delete feed/topic."
123+msgstr ""
124+
125+#: ../qml/pages/PageHelp.qml:223
126+msgid "Seems you are living in: "
127+msgstr ""
128+
129+#: ../qml/pages/PageHelp.qml:232
130+msgid ""
131+"Some regions/countries(e.g. China) may block Google service, if you're "
132+"living there or plan to go there, we suggest to trun off the build-in Google "
133+"RSS service in settings page, or nothing you should care."
134+msgstr ""
135+
136+#: ../qml/pages/PageHelp.qml:239
137+msgid ""
138+"We detect that you're living in some region/country(e.g. China) which blocks "
139+"Google service, so Shorts disable the build-in Google RSS service by "
140+"default. You still can turn it on here or in settings page."
141+msgstr ""
142+
143+#: ../qml/pages/PageHelp.qml:250
144+msgid "Use Google RSS engine: "
145+msgstr ""
146+
147+#: ../qml/pages/PageHelp.qml:287
148+msgid "Enjoy !"
149+msgstr ""
150+
151+#: ../qml/pages/PageHelp.qml:297
152+msgid "Do not show this help page again "
153+msgstr ""
154+
155+#: ../qml/pages/PageHelp.qml:316
156+msgid "Start using Shorts !"
157+msgstr ""
158+
159+#: ../qml/pages/PageHelp.qml:340
160+msgid "Skip"
161+msgstr ""
162+
163+#: ../qml/pages/PageInfo.qml:10
164+msgid "About Shorts"
165+msgstr ""
166+
167+#: ../qml/pages/PageInfo.qml:39
168+msgid "Author"
169+msgstr ""
170+
171+#: ../qml/pages/PageInfo.qml:53
172+msgid "Copyleft"
173+msgstr ""
174+
175+#: ../qml/pages/PageInfo.qml:57
176+msgid "License with GPLv3"
177+msgstr ""
178+
179+#: ../qml/pages/PageInfo.qml:62
180+msgid ""
181+"Ubuntu Shorts App is the official rss reader app for Ubuntu Touch. We follow "
182+"an open source model where the code is available to anyone to branch and "
183+"hack on. The ubuntu shorts app follows a test driven development (TDD) where "
184+"tests are written in parallel to feature implementation to help spot "
185+"regressions easier."
186+msgstr ""
187+
188+#: ../qml/pages/PageInfo.qml:68
189+msgid "Click here to report a bug"
190+msgstr ""
191+
192+#: ../qml/pages/PageSettings.qml:9 ../qml/shorts-app.qml:249
193 msgid "Settings"
194 msgstr ""
195
196-#: ../qml/pages/PageSettings.qml:38
197+#: ../qml/pages/PageSettings.qml:15
198+msgid "Help"
199+msgstr ""
200+
201+#: ../qml/pages/PageSettings.qml:20
202+msgid "Info"
203+msgstr ""
204+
205+#: ../qml/pages/PageSettings.qml:51
206 msgid ""
207-"For those who living in some special regions cannot access Google, the "
208-"switch below can disable Google RSS engine, Shorts will directly gets data "
209-"from RSS sources."
210+"Some special regions/countries block Google service, we suggest to turn off "
211+"the switch below if living in there."
212 msgstr ""
213
214-#: ../qml/pages/PageSettings.qml:46
215+#: ../qml/pages/PageSettings.qml:59
216 msgid "Use Google Search: "
217 msgstr ""
218
219-#: ../qml/pages/PageSettings.qml:71
220+#: ../qml/pages/PageSettings.qml:84
221 msgid ""
222 "For those users, who want to import their RSS feeds from other sources, "
223 "please press the button below."
224 msgstr ""
225
226-#: ../qml/pages/PageSettings.qml:81
227-msgid "Import OMPL"
228+#: ../qml/pages/PageSettings.qml:94
229+msgid "Import OPML"
230 msgstr ""
231
232-#: ../qml/pages/TopicManagement.qml:13 ../qml/shorts-app.qml:219
233+#: ../qml/pages/TopicManagement.qml:13 ../qml/shorts-app.qml:229
234 msgid "Edit topics"
235 msgstr ""
236
237@@ -234,88 +360,50 @@
238 msgid "Add Feed"
239 msgstr ""
240
241-#: ../qml/shorts-app.qml:186
242+#: ../qml/shorts-app.qml:196
243 msgid "Refresh"
244 msgstr ""
245
246-#: ../qml/shorts-app.qml:193
247+#: ../qml/shorts-app.qml:203
248 msgid "Grid View"
249 msgstr ""
250
251-#: ../qml/shorts-app.qml:193
252+#: ../qml/shorts-app.qml:203
253 msgid "List view"
254 msgstr ""
255
256-#: ../qml/shorts-app.qml:229
257+#: ../qml/shorts-app.qml:239
258 msgid "Disable night mode"
259 msgstr ""
260
261-#: ../qml/shorts-app.qml:229
262+#: ../qml/shorts-app.qml:239
263 msgid "Enable night mode"
264 msgstr ""
265
266-#: ../qml/shorts-app.qml:321
267+#: ../qml/shorts-app.qml:334
268 msgid "Saved"
269 msgstr ""
270
271-#: ../qml/shorts-app.qml:329 shorts.desktop.in.in.h:1
272+#: ../qml/shorts-app.qml:342 shorts.desktop.in.in.h:1
273 msgid "Shorts"
274 msgstr ""
275
276-#: ../qml/shorts-app.qml:473
277+#: ../qml/shorts-app.qml:486
278 msgid "Checking for new articles"
279 msgstr ""
280
281-#: ../qml/shorts-app.qml:497
282+#: ../qml/shorts-app.qml:510
283 msgid "Perhaps some of the channels have not been updated."
284 msgstr ""
285
286-#: ../qml/shorts-app.qml:498
287+#: ../qml/shorts-app.qml:511
288 msgid "Errors occurred during the update"
289 msgstr ""
290
291-#: ../qml/shorts-app.qml:516
292-msgid "+ Add feeds"
293-msgstr ""
294-
295-#: ../qml/shorts-app.qml:528
296-msgid "Add online accounts"
297-msgstr ""
298-
299-#: ../qml/shorts-app.qml:531
300-msgid "Online accounts are not available for now"
301-msgstr ""
302-
303-#: ../qml/shorts-app.qml:532 ../qml/shorts-app.qml:541
304-msgid "We are sorry"
305-msgstr ""
306-
307-#: ../qml/shorts-app.qml:537
308-msgid "Import subscriptions"
309-msgstr ""
310-
311-#: ../qml/shorts-app.qml:540
312-msgid "Importing subscriptions is not available for now"
313-msgstr ""
314-
315-#: ../qml/shorts-app.qml:555
316+#: ../qml/shorts-app.qml:525
317 msgid "Ok"
318 msgstr ""
319
320-#: ../qml/shorts-app.qml:569
321-msgid ""
322-"Shorts detects that you're located in an area which blocks Google's IP."
323-"<br><br>"
324-msgstr ""
325-
326-#: ../qml/shorts-app.qml:574
327-msgid "Yes, please."
328-msgstr ""
329-
330-#: ../qml/shorts-app.qml:584
331-msgid "No, thanks."
332-msgstr ""
333-
334 #: ../qml/tabs/BaseTab.qml:153
335 msgid "There are no articles to show"
336 msgstr ""
337
338=== modified file 'shorts/qml/components/NetworkManager.qml'
339--- shorts/qml/components/NetworkManager.qml 2016-01-16 10:55:38 +0000
340+++ shorts/qml/components/NetworkManager.qml 2016-03-18 09:56:42 +0000
341@@ -183,7 +183,7 @@
342 property var googleFeedApi: GoogleFeedApi {
343 onLoadResult: {
344 if (result.responseStatus !== 200) {
345- console.log("XML NETWORK GFA:", JSON.stringify(result))
346+// console.log("XML NETWORK GFA:", JSON.stringify(result))
347 if (operationStatus == "success")
348 operationStatus = "withErrors"
349 } else d.updateFeedInfo(d.currentFeed.id, d.currentFeed.link, result.responseData)
350@@ -195,7 +195,7 @@
351 property var nonGoogleFeedApi: XmlNetwork {
352 onLoadResult: {
353 if (!result.rss) {
354- console.log("XML NETWORK NGA:", JSON.stringify(result))
355+// console.log("XML NETWORK NGA:", JSON.stringify(result))
356 if (operationStatus == "success")
357 operationStatus = "withErrors"
358 } else d.updateFeedInfoNg(d.currentFeed.id, d.currentFeed.link, result.rss.channel)
359
360=== modified file 'shorts/qml/components/OptionsKeeper.qml'
361--- shorts/qml/components/OptionsKeeper.qml 2016-01-04 11:46:35 +0000
362+++ shorts/qml/components/OptionsKeeper.qml 2016-03-18 09:56:42 +0000
363@@ -3,6 +3,10 @@
364
365 /* New interface for options.
366 * Currently it is just facade on U1DB.
367+ *
368+ * ******* New changes, since 27.Feb.2016
369+ * We decide to replace U1DB with QSettings, which is more reliable & light weight
370+ * properties & functions remain the same
371 */
372 Item {
373
374@@ -11,70 +15,91 @@
375 property bool useListMode
376 property bool useGoogleSearch
377
378+ property bool needPopup
379+
380 Component.onCompleted: {
381+ // initial first use of QSettings
382+ if (utilities.getSetting("firstSetting") == "") {
383+ utilities.setSetting("firstSetting", "used!")
384+ utilities.setSetting("needPopup", "true")
385+ utilities.setSetting("dbVersion", "1.2")
386+ utilities.setSetting("fontSize", String(settingsDocument.contents.fontSize))
387+ utilities.setSetting("useDarkTheme", String(settingsDocument.contents.useDarkTheme))
388+ utilities.setSetting("useListMode", String(settingsDocument.contents.useListMode))
389+ utilities.setSetting("useGoogleSearch", "true")
390+ }
391+
392 fontSize = getFontSize()
393 useDarkTheme = getUseDarkTheme()
394 useListMode = getUseListMode()
395 useGoogleSearch = getUseGoogleSearch()
396+ needPopup = getNeedPopup()
397 }
398
399 onFontSizeChanged: setFontSize(fontSize)
400 onUseDarkThemeChanged: setUseDarkTheme(useDarkTheme)
401 onUseListModeChanged: setUseListMode(useListMode)
402 onUseGoogleSearchChanged: setUseGoogleSearch(useGoogleSearch)
403+ onNeedPopupChanged: setNeedPopup(needPopup)
404+
405+ function getNeedPopup() {
406+ var tmp = utilities.getSetting("needPopup")
407+ if (tmp == "true") return true
408+ if (tmp == "false") return false
409+ }
410+
411+ function setNeedPopup(value) {
412+ utilities.setSetting("needPopup", String(value))
413+ }
414
415 function getFontSize() {
416- return settingsDocument.contents.fontSize
417+ return Number(utilities.getSetting("fontSize"))
418 }
419
420 function setFontSize(value) {
421- var cont = settingsDocument.contents
422- cont.fontSize = value
423- settingsDocument.contents = cont
424+ utilities.setSetting("fontSize", String(value))
425 }
426
427 function getUseDarkTheme() {
428- return settingsDocument.contents.useDarkTheme
429+ var tmp = utilities.getSetting("useDarkTheme")
430+ if (tmp == "true") return true
431+ if (tmp == "false") return false
432 }
433
434 function setUseDarkTheme(value) {
435- var cont = settingsDocument.contents
436- cont.useDarkTheme = value
437- settingsDocument.contents = cont
438+ utilities.setSetting("useDarkTheme", String(value))
439 }
440
441 function getUseListMode() {
442- return settingsDocument.contents.useListMode
443+ var tmp = utilities.getSetting("useListMode")
444+ if (tmp == "true") return true
445+ if (tmp == "false") return false
446 }
447
448 function setUseListMode(value) {
449- var cont = settingsDocument.contents
450- cont.useListMode = value
451- settingsDocument.contents = cont
452+ utilities.setSetting("useListMode", String(value))
453 }
454
455 function dbVersion() {
456- return settingsDocument.contents.dbVersion
457+ return utilities.getSetting("dbVersion")
458 }
459
460 function setDbVersion(value) {
461- var cont = settingsDocument.contents
462- cont.dbVersion = value
463- settingsDocument.contents = cont
464+ utilities.setSetting("dbVersion", String(value))
465 }
466
467 function dbLastUpdate() {
468- return settingsDocument.contents.dbLastUpdate
469+// return settingsDocument.contents.dbLastUpdate
470 }
471
472 function getUseGoogleSearch() {
473- return settingsDocument.contents.useGoogleSearch
474+ var tmp = utilities.getSetting("useGoogleSearch")
475+ if (tmp == "true") return true
476+ if (tmp == "false") return false
477 }
478
479 function setUseGoogleSearch(value) {
480- var cont = settingsDocument.contents
481- cont.useGoogleSearch = value
482- settingsDocument.contents = cont
483+ utilities.setSetting("useGoogleSearch", String(value))
484 }
485
486 U1db.Database {
487@@ -88,7 +113,7 @@
488 docId: 'settingsDocument'
489 create: true
490 defaults: { "useDarkTheme" : false, "fontSize" : 1,
491- "useListMode" : false, "dbVersion" : 1.2,
492+ "useListMode" : false, "dbVersion" : "1.2",
493 "useGoogleSearch" : true
494 }
495 }
496
497=== added file 'shorts/qml/components/SettingsItem.qml'
498--- shorts/qml/components/SettingsItem.qml 1970-01-01 00:00:00 +0000
499+++ shorts/qml/components/SettingsItem.qml 2016-03-18 09:56:42 +0000
500@@ -0,0 +1,120 @@
501+/*
502+ * Flashback - Entertainment app for Ubuntu
503+ * Copyright (C) 2013, 2014 Nekhelesh Ramananthan <nik90@ubuntu.com>
504+ *
505+ * This program is free software: you can redistribute it and/or modify
506+ * it under the terms of the GNU General Public License version 3 as
507+ * published by the Free Software Foundation.
508+ *
509+ * This program is distributed in the hope that it will be useful,
510+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
511+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
512+ * GNU General Public License for more details.
513+ *
514+ * You should have received a copy of the GNU General Public License
515+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
516+ *
517+ */
518+
519+import QtQuick 2.2
520+import Ubuntu.Components 1.1
521+import Ubuntu.Components.ListItems 1.0 as ListItem
522+
523+UbuntuShape {
524+ id: settingsItem
525+
526+ // Property to set the contents of the settings item
527+ property alias contents: _contents.data
528+
529+ // Property to set the header of the settings item
530+ property string title: "Default"
531+
532+ // Property to set the icon of the settings item header
533+ property alias icon: _icon.source
534+
535+ // Property to set the vertical spacing in the contents column
536+ property alias contentSpacing: _contents.spacing
537+
538+ radius: "medium"
539+ color: Qt.rgba(0,0,0,0.15)
540+ height: _titleContainer.height + _contentsContainer.height + units.gu(2)
541+
542+ anchors {
543+ left: parent.left
544+ right: parent.right
545+ }
546+
547+ Item {
548+ id: _titleContainer
549+
550+ clip: true
551+ height: _title.height + units.gu(3)
552+ anchors {
553+ top: parent.top
554+ left: parent.left
555+ right: parent.right
556+ }
557+
558+ UbuntuShape {
559+ id: _header
560+ radius: "medium"
561+ color: Qt.rgba(0,0,0,0.2)
562+ height: _title.height + units.gu(5)
563+ anchors {
564+ top: parent.top
565+ left: parent.left
566+ right: parent.right
567+ }
568+ }
569+
570+ Row {
571+ spacing: units.gu(1)
572+ anchors {
573+ left: parent.left
574+ leftMargin: units.gu(2)
575+ top: parent.top
576+ topMargin: units.gu(1.5)
577+ }
578+
579+ Image {
580+ id: _icon
581+ source: ""
582+ height: _title.height
583+ fillMode: Image.PreserveAspectFit
584+ visible: source == "" ? false : true
585+ }
586+
587+ Label {
588+ id: _title
589+ text: title
590+ font.pixelSize: units.dp(17)
591+ }
592+ }
593+ }
594+
595+ Rectangle {
596+ id: customDivider
597+ anchors .top: _titleContainer.bottom
598+ width: parent.width
599+ height: units.gu(0.1)
600+ color: UbuntuColors.orange
601+ }
602+
603+ Column {
604+ id: _contentsContainer
605+
606+ anchors {
607+ bottomMargin: units.gu(1)
608+ bottom: parent.bottom
609+ left: parent.left
610+ right: parent.right
611+ }
612+
613+ Column {
614+ id: _contents
615+ spacing: units.gu(1)
616+ width: parent.width
617+ clip: true
618+ }
619+ }
620+}
621
622=== modified file 'shorts/qml/icons/CMakeLists.txt'
623--- shorts/qml/icons/CMakeLists.txt 2015-07-17 14:42:42 +0000
624+++ shorts/qml/icons/CMakeLists.txt 2016-03-18 09:56:42 +0000
625@@ -1,4 +1,4 @@
626-file(GLOB ICONS *.svg)
627+file(GLOB ICONS *.svg *.png)
628
629 # make the files visible in the qtcreator tree
630 add_custom_target(ubuntu-rssreader-app_icons_QMlFiles ALL SOURCES ${ICONS})
631
632=== added file 'shorts/qml/icons/help1.png'
633Binary files shorts/qml/icons/help1.png 1970-01-01 00:00:00 +0000 and shorts/qml/icons/help1.png 2016-03-18 09:56:42 +0000 differ
634=== added file 'shorts/qml/icons/help2.png'
635Binary files shorts/qml/icons/help2.png 1970-01-01 00:00:00 +0000 and shorts/qml/icons/help2.png 2016-03-18 09:56:42 +0000 differ
636=== added file 'shorts/qml/icons/help3.png'
637Binary files shorts/qml/icons/help3.png 1970-01-01 00:00:00 +0000 and shorts/qml/icons/help3.png 2016-03-18 09:56:42 +0000 differ
638=== added file 'shorts/qml/icons/shorts.png'
639Binary files shorts/qml/icons/shorts.png 1970-01-01 00:00:00 +0000 and shorts/qml/icons/shorts.png 2016-03-18 09:56:42 +0000 differ
640=== modified file 'shorts/qml/nongoogle/Positioner.qml'
641--- shorts/qml/nongoogle/Positioner.qml 2016-01-04 11:46:35 +0000
642+++ shorts/qml/nongoogle/Positioner.qml 2016-03-18 09:56:42 +0000
643@@ -32,6 +32,8 @@
644 // Property to keep track of app cold start status
645 property string countryCode: ""
646
647+ signal locationDetected(var location)
648+
649 Component.onCompleted: {
650 }
651
652@@ -94,12 +96,13 @@
653
654 countryCode = resObj.countryName
655 print("countryCode", resObj)
656+ locationDetected(countryCode)
657
658- if (countryCode == "China") {
659- if (optionsKeeper.useGoogleSearch) {
660- PopupUtils.open(componentDialogNG, tabstabs)
661- }
662- }
663+// if (countryCode == "China") {
664+// if (optionsKeeper.useGoogleSearch) {
665+// PopupUtils.open(componentDialogNG, tabstabs)
666+// }
667+// }
668 }
669 }
670
671
672=== modified file 'shorts/qml/nongoogle/XmlNetwork.qml'
673--- shorts/qml/nongoogle/XmlNetwork.qml 2016-01-04 11:13:30 +0000
674+++ shorts/qml/nongoogle/XmlNetwork.qml 2016-03-18 09:56:42 +0000
675@@ -1,4 +1,5 @@
676 import QtQuick 2.4
677+import "../utils/xml2json.js" as XJ
678
679 QtObject {
680 id: rootObject
681@@ -28,13 +29,18 @@
682 if (doc.readyState === XMLHttpRequest.DONE) {
683
684 var resObj
685+// print ("status & text: ", doc.status, doc.statusText, doc.responseText)
686 if (doc.status == 200) {
687- resObj = utilities.xmlToJson(doc.responseText)
688+ resObj = utilities.xmlToJson(doc.responseText)
689+// resObj = utilities.xmlToJson(doc.responseText)
690+// var x2js = new XJ.X2JS();
691+// resObj = XJ.xmlToJSON.parseString(doc.responseText) //x2js.xml_str2json( doc.responseText );
692 } else { // Error
693 resObj = {"responseDetails" : doc.statusText,
694 "responseStatus" : doc.status}
695 }
696
697+ print ("resObj: ", resObj.rss )
698 __doc = null
699 loadResult(resObj)
700 }
701
702=== added file 'shorts/qml/pages/PageHelp.qml'
703--- shorts/qml/pages/PageHelp.qml 1970-01-01 00:00:00 +0000
704+++ shorts/qml/pages/PageHelp.qml 2016-03-18 09:56:42 +0000
705@@ -0,0 +1,371 @@
706+import QtQuick 2.4
707+//import QtQml.Models 2.1
708+import Ubuntu.Components 1.3
709+import Ubuntu.Components.ListItems 1.3 as ListItem
710+
711+import "../nongoogle"
712+
713+
714+
715+Page {
716+ id: pageHelp
717+ title: {
718+ switch (view.currentIndex) {
719+ case 0 :
720+ return i18n.tr("Welcome to Shorts")
721+ case 1 :
722+ return i18n.tr("View Articles")
723+ case 2 :
724+ return i18n.tr("Search RSS")
725+ case 3 :
726+ return i18n.tr("Manage topics and feeds")
727+ case 4 :
728+ return i18n.tr("Location")
729+ case 5 :
730+ return i18n.tr("Enjoy")
731+ }
732+ }
733+
734+ flickable: null
735+// head.visible: false
736+ head.backAction:
737+ Action { // just replace the default one
738+ visible: false
739+ iconName: "close"
740+ }
741+
742+ // property to log who push me to stack ..
743+ property var pushOwner
744+
745+ property bool dontShowAgain: true
746+ property alias useGoogleRSS: swUseGfa.checked
747+
748+ function backToPushOwner(isSkip) {
749+ if (isSkip) {
750+ optionsKeeper.needPopup = true
751+ }
752+ else {
753+ if (dontShowAgain) {
754+ optionsKeeper.needPopup = false
755+ }
756+ else {
757+ optionsKeeper.needPopup = true
758+ }
759+
760+// if (positionDetector.countryCode == "China") {
761+// optionsKeeper.useGoogleSearch = false
762+// }
763+ optionsKeeper.useGoogleSearch = useGoogleRSS
764+ }
765+
766+ // call startup function in MainView, do nothing when other pages push this page
767+ try {
768+ pushOwner.startup()
769+ }
770+ catch (er) {
771+ // TODO show error
772+ }
773+ pageStack.pop()
774+ }
775+
776+ // Positioner to detect current position
777+ Positioner {
778+ id: positionDetector
779+ }
780+
781+ VisualItemModel {
782+ id: itemModel
783+
784+ ////////////////////////////////////////////////// tutorial 1 welcome screen, show what this app can do
785+ Item {
786+ width: view.width; height: view.height
787+ Column {
788+ anchors.fill: parent
789+ anchors.margins: units.gu(2)
790+ spacing: units.gu(1)
791+
792+// Label {
793+// anchors { left: parent.left; right: parent.right }
794+// text: i18n.tr("xxxxxxxxxxxxxxxxx")
795+// fontSize: "large"
796+// font.bold: true
797+// horizontalAlignment: Text.AlignHCenter
798+// wrapMode: Text.WrapAtWordBoundaryOrAnywhere
799+// }
800+ Image {
801+ anchors.horizontalCenter: parent.horizontalCenter
802+ source: "../icons/shorts.png"
803+ width: units.gu(15); height: width
804+ fillMode: Image.PreserveAspectFit
805+ }
806+
807+ Item { width: units.gu(2); height: width }
808+ Label {
809+ anchors { left: parent.left; right: parent.right }
810+ text: i18n.tr("Shorts is an RSS reader app developed by Canonical & Ubuntu Comunity.")
811+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
812+ }
813+ Label {
814+ anchors { left: parent.left; right: parent.right }
815+ text: i18n.tr("Shorts provides most primary features which also can be seen in other RSS reader apps, with a beautiful Ubuntu style user interface.")
816+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
817+// font.bold: true
818+ }
819+ Item { width: units.gu(11); height: width }
820+ Label {
821+ anchors { left: parent.left; right: parent.right }
822+ text: i18n.tr("Swipe left to continue.")
823+ font.italic: true
824+ horizontalAlignment: Text.AlignHCenter
825+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
826+ }
827+
828+ }
829+ }
830+
831+ ////////////////////////////////////////////////// tutorial 2 rss screen
832+ Item {
833+ width: view.width; height: view.height
834+ Column {
835+ anchors.fill: parent
836+ anchors.margins: units.gu(2)
837+ spacing: units.gu(1)
838+
839+ Label {
840+ anchors { left: parent.left; right: parent.right }
841+ text: i18n.tr("Scroll left/right in grid mode or scroll up/down in list mode.")
842+// fontSize: "large"
843+// font.bold: true
844+ horizontalAlignment: Text.AlignHCenter
845+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
846+ }
847+ Image {
848+ anchors.horizontalCenter: parent.horizontalCenter
849+ source: "../icons/help1.png"
850+ anchors { left: parent.left; right: parent.right }
851+ height: width
852+ fillMode: Image.PreserveAspectFit
853+ }
854+
855+ }
856+ }
857+
858+ ////////////////////////////////////////////////// tutorial 3 search screen
859+ Item {
860+ width: view.width; height: view.height
861+ Column {
862+ anchors.fill: parent
863+ anchors.margins: units.gu(2)
864+ spacing: units.gu(1)
865+
866+ Label {
867+ anchors { left: parent.left; right: parent.right }
868+ text: i18n.tr("Swipe up will enter this search page, just type any simple words, or paste a link.")
869+// fontSize: "large"
870+// font.bold: true
871+ horizontalAlignment: Text.AlignHCenter
872+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
873+ }
874+ Image {
875+ anchors.horizontalCenter: parent.horizontalCenter
876+ source: "../icons/help2.png"
877+ anchors { left: parent.left; right: parent.right }
878+ height: width
879+ fillMode: Image.PreserveAspectFit
880+ }
881+
882+ }
883+ }
884+
885+ ////////////////////////////////////////////////// tutorial 4 topic screen
886+ Item {
887+ width: view.width; height: view.height
888+ Column {
889+ anchors.fill: parent
890+ anchors.margins: units.gu(2)
891+ spacing: units.gu(1)
892+
893+ Label {
894+ anchors { left: parent.left; right: parent.right }
895+ text: i18n.tr("Every feed must belong to one topic, swipe one item to delete feed/topic.")
896+// fontSize: "large"
897+// font.bold: true
898+ horizontalAlignment: Text.AlignHCenter
899+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
900+ }
901+// Label {
902+// anchors { left: parent.left; right: parent.right }
903+// text: i18n.tr("1. Normally, users are no need to care about their settings, default setting will work fine for most cases.")
904+// wrapMode: Text.WrapAtWordBoundaryOrAnywhere
905+// }
906+ Image {
907+ anchors.horizontalCenter: parent.horizontalCenter
908+ source: "../icons/help3.png"
909+ anchors { left: parent.left; right: parent.right }
910+ height: width
911+ fillMode: Image.PreserveAspectFit
912+ }
913+
914+
915+ }
916+ }
917+
918+ ////////////////////////////////////////////////// tutorial 5 location screen & tips about non-google setting
919+ Item {
920+ width: view.width; height: view.height
921+ Column {
922+ anchors.fill: parent
923+ anchors.margins: units.gu(2)
924+ spacing: units.gu(1)
925+
926+ Label {
927+ anchors { left: parent.left; right: parent.right }
928+ text: i18n.tr("Seems you are living in: ") + positionDetector.countryCode
929+// fontSize: "large"
930+// font.bold: true
931+ horizontalAlignment: Text.AlignHCenter
932+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
933+ }
934+
935+ Label {
936+ anchors { left: parent.left; right: parent.right }
937+ text: i18n.tr("Some regions/countries(e.g. China) may block Google service, if you're living there or plan to go there, we suggest to trun off the build-in Google RSS service in settings page, or nothing you should care.")
938+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
939+ visible: positionDetector.countryCode != "China"
940+ }
941+
942+ Label {
943+ anchors { left: parent.left; right: parent.right }
944+ text: i18n.tr("We detect that you're living in some region/country(e.g. China) which blocks Google service, so Shorts disable the build-in Google RSS service by default. You still can turn it on here or in settings page.")
945+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
946+ visible: positionDetector.countryCode == "China"
947+ }
948+
949+ Item { width: 10; height: units.gu(1); } // just a separator
950+
951+ ListItem.ThinDivider{ }
952+
953+ ListItem.Standard {
954+ visible: positionDetector.countryCode == "China"
955+ text: i18n.tr("Use Google RSS engine: ")
956+ control:
957+ Switch {
958+ id: swUseGfa
959+ anchors.right: parent.right
960+ checked: true
961+
962+ Connections {
963+ target: positionDetector
964+ onLocationDetected: {
965+ if (location == "China") {
966+ swUseGfa.checked = false
967+ }
968+ else swUseGfa.checked = true
969+ }
970+ }
971+
972+ onCheckedChanged: {
973+ //
974+ }
975+ }
976+ }
977+
978+
979+ }
980+ }
981+
982+ ////////////////////////////////////////////////// tutorial 6 end screen & do not show this again
983+ Item {
984+ width: view.width; height: view.height
985+ Column {
986+ anchors.fill: parent
987+ anchors.margins: units.gu(2)
988+ spacing: units.gu(1)
989+
990+ Label {
991+ anchors { left: parent.left; right: parent.right }
992+ text: i18n.tr("Enjoy !")
993+ fontSize: "large"
994+ font.bold: true
995+ horizontalAlignment: Text.AlignHCenter
996+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
997+ }
998+
999+ ListItem.ThinDivider{ }
1000+
1001+ ListItem.Standard {
1002+ text: i18n.tr("Do not show this help page again ")
1003+ control:
1004+ Switch {
1005+ id: xxxxxxxxxx
1006+ anchors.right: parent.right
1007+ checked: true
1008+
1009+ onCheckedChanged: {
1010+ dontShowAgain = checked
1011+ }
1012+ }
1013+ }
1014+
1015+
1016+ }
1017+
1018+ Button {
1019+ anchors { centerIn: parent }
1020+ color: UbuntuColors.orange
1021+ text: i18n.tr("Start using Shorts !")
1022+ onClicked: { backToPushOwner(false) }
1023+ }
1024+ }
1025+ }
1026+
1027+ ListView {
1028+ id: view
1029+ anchors { fill: parent; bottomMargin: units.gu(6); topMargin: units.gu(1) }
1030+ model: itemModel
1031+ preferredHighlightBegin: 0; preferredHighlightEnd: 0
1032+ highlightRangeMode: ListView.StrictlyEnforceRange
1033+ orientation: ListView.Horizontal
1034+ snapMode: ListView.SnapOneItem;
1035+ cacheBuffer: 999999
1036+ }
1037+
1038+ MouseArea {
1039+ width: units.gu(8); height: units.gu(7)
1040+ anchors.bottom: parent.bottom
1041+ onClicked: { backToPushOwner(true) }
1042+
1043+ Label{ /*anchors.horizontalCenter: parent.horizontalCenter;*/
1044+ anchors.centerIn: parent
1045+ text: i18n.tr("Skip")
1046+ font.italic: true
1047+ }
1048+ }
1049+
1050+ // bottom indicator
1051+ Item {
1052+ width: pageHelp.width; height: units.gu(6)
1053+ anchors { top: view.bottom; bottom: parent.bottom }
1054+
1055+ Row {
1056+ anchors.centerIn: parent
1057+ spacing: units.gu(1.8)
1058+
1059+ Repeater {
1060+ model: itemModel.count
1061+
1062+ Rectangle {
1063+ width: units.gu(1) ; height: width
1064+ radius: width
1065+ color: view.currentIndex == index ? "blue" : "white"
1066+
1067+ MouseArea {
1068+ width: units.gu(2); height: width
1069+ anchors.centerIn: parent
1070+ onClicked: view.currentIndex = index
1071+ }
1072+ }
1073+ }
1074+ }
1075+ }
1076+}
1077
1078=== added file 'shorts/qml/pages/PageInfo.qml'
1079--- shorts/qml/pages/PageInfo.qml 1970-01-01 00:00:00 +0000
1080+++ shorts/qml/pages/PageInfo.qml 2016-03-18 09:56:42 +0000
1081@@ -0,0 +1,79 @@
1082+import QtQuick 2.4
1083+import Ubuntu.Components 1.3
1084+import Ubuntu.Components.ListItems 1.3 as ListItem
1085+import "../components"
1086+
1087+Page {
1088+ id: pageInfo
1089+
1090+ flickable: null
1091+ title: i18n.tr("About Shorts")
1092+
1093+ ///////////////////////////// main content
1094+ Flickable {
1095+ id: scrollArea
1096+ boundsBehavior: (contentHeight > height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
1097+ anchors.fill: parent
1098+ contentWidth: width
1099+ contentHeight: columnInnerArea.height + units.gu(3)
1100+ clip: true
1101+
1102+ Column {
1103+ id: columnInnerArea
1104+ spacing: units.gu(2)
1105+ anchors {
1106+ top: parent.top;
1107+ margins: units.gu(1)
1108+ left: parent.left; right: parent.right
1109+ }
1110+ height: childrenRect.height
1111+
1112+ Image {
1113+ anchors.horizontalCenter: parent.horizontalCenter
1114+ source: "../icons/shorts.png"
1115+ width: units.gu(15); height: width
1116+ fillMode: Image.PreserveAspectFit
1117+ }
1118+
1119+ SettingsItem {
1120+ title: i18n.tr("Author")
1121+ contents: [
1122+
1123+ ListItem.Standard {
1124+ text: "Roman Shchekin <mrqtros@gmail.com>"
1125+ },
1126+
1127+ ListItem.Standard {
1128+ text: "Joey Chan <joeychan.ubuntu@gmail.com>"
1129+ }
1130+ ]
1131+ }
1132+
1133+ SettingsItem {
1134+ title: i18n.tr("Copyleft")
1135+ contents: [
1136+ //
1137+ ListItem.Standard {
1138+ text: i18n.tr("License with GPLv3")
1139+ showDivider: false
1140+ },
1141+
1142+ Label {
1143+ text: i18n.tr("Ubuntu Shorts App is the official rss reader app for Ubuntu Touch. We follow an open source model where the code is available to anyone to branch and hack on. The ubuntu shorts app follows a test driven development (TDD) where tests are written in parallel to feature implementation to help spot regressions easier.")
1144+ anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
1145+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
1146+ },
1147+
1148+ ListItem.Standard {
1149+ text: "<b>" + i18n.tr("Click here to report a bug") + "</b>"
1150+ showDivider: false
1151+ MouseArea {
1152+ anchors.fill: parent
1153+ onClicked: Qt.openUrlExternally("https://bugs.launchpad.net/ubuntu-rssreader-app/+filebug")
1154+ }
1155+ }
1156+ ]
1157+ }
1158+ }
1159+ }
1160+}
1161
1162=== modified file 'shorts/qml/pages/PageSettings.qml'
1163--- shorts/qml/pages/PageSettings.qml 2016-01-14 15:35:31 +0000
1164+++ shorts/qml/pages/PageSettings.qml 2016-03-18 09:56:42 +0000
1165@@ -9,6 +9,19 @@
1166 title: i18n.tr("Settings")
1167 flickable: null
1168
1169+ head.actions: [
1170+ Action {
1171+ iconName: "help"
1172+ text: i18n.tr("Help")
1173+ onTriggered: pageStack.push(Qt.resolvedUrl("./PageHelp.qml")/*, {pushOwner: pageSettings }*/)
1174+ },
1175+ Action {
1176+ iconName: "info"
1177+ text: i18n.tr("Info")
1178+ onTriggered: pageStack.push(Qt.resolvedUrl("./PageInfo.qml")/*, {pushOwner: pageSettings }*/)
1179+ }
1180+ ]
1181+
1182 property bool preventSave: false
1183
1184 Component.onCompleted: updateInfoFromOptions()
1185@@ -35,7 +48,7 @@
1186 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
1187 horizontalAlignment: Text.AlignHCenter
1188 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
1189- text: i18n.tr("For those who living in some special regions cannot access Google, the switch below can disable Google RSS engine, Shorts will directly gets data from RSS sources.")
1190+ text: i18n.tr("Some special regions/countries block Google service, we suggest to turn off the switch below if living in there.")
1191 }
1192
1193 Item { width: 10; height: units.gu(1); } // just a separator
1194@@ -78,7 +91,7 @@
1195 Button {
1196 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
1197 anchors.horizontalCenter: parent.horizontalCenter
1198- text: i18n.tr("Import OMPL")
1199+ text: i18n.tr("Import OPML")
1200
1201 onClicked: {
1202 pageStack.push(Qt.resolvedUrl("../content/ImportFeeds.qml")) ;
1203
1204=== modified file 'shorts/qml/shorts-app.qml'
1205--- shorts/qml/shorts-app.qml 2016-01-16 10:55:38 +0000
1206+++ shorts/qml/shorts-app.qml 2016-03-18 09:56:42 +0000
1207@@ -31,7 +31,20 @@
1208 backgroundColor: "#F5F5F5"
1209
1210 Component.onCompleted: {
1211-
1212+ // show help page in first use
1213+ if (optionsKeeper.needPopup) {
1214+ pageStack.push(Qt.resolvedUrl("./pages/PageHelp.qml"), {pushOwner: mainView })
1215+ // the help page will call the startup() function by using the pushOwner property
1216+ }
1217+ else {
1218+ startup()
1219+ }
1220+
1221+
1222+ }
1223+
1224+ // seperate following code to a "startup" function from Component.onCompleted above
1225+ function startup() {
1226 var dbParams = {"isRefreshRequired" : false,
1227 "oldDbVersion" : optionsKeeper.dbVersion(),
1228 "newDbVersion" : ""
1229@@ -457,9 +470,9 @@
1230 }
1231
1232 // Positioner to detect current position
1233- Positioner {
1234- id: positionDetector
1235- }
1236+// Positioner {
1237+// id: positionDetector
1238+// }
1239
1240 /* -------------------------- Components ---------------------------- */
1241
1242@@ -517,33 +530,33 @@
1243 } // Component
1244
1245 //////////////////////////////////////////////////////// a dialog to ask user if she/he wants to turn off the google search
1246- Component {
1247- id: componentDialogNG
1248-
1249- Dialog {
1250- id: dialogNG
1251- title: i18n.tr("Warning")
1252- text: i18n.tr("Shorts detects that you're located in an area which blocks Google's IP.<br><br>"
1253- + "We strongly reconmend you to turn off the Google search funtion."
1254- + "Or you can do it in the settings page manually.")
1255-
1256- Button {
1257- text: i18n.tr("Yes, please.")
1258- color: UbuntuColors.orange
1259- objectName: "dialogNGButtonYes"
1260- onClicked: {
1261- optionsKeeper.setUseGoogleSearch(false)
1262- PopupUtils.close(dialogNG)
1263- }
1264- }
1265-
1266- Button {
1267- text: i18n.tr("No, thanks.")
1268- objectName: "dialogNGButtonNo"
1269- onClicked: PopupUtils.close(dialogNG)
1270- }
1271- }
1272- } // Component
1273+// Component {
1274+// id: componentDialogNG
1275+
1276+// Dialog {
1277+// id: dialogNG
1278+// title: i18n.tr("Warning")
1279+// text: i18n.tr("Shorts detects that you're located in an area which blocks Google's IP.<br><br>"
1280+// + "We strongly reconmend you to turn off the Google search funtion."
1281+// + "Or you can do it in the settings page manually.")
1282+
1283+// Button {
1284+// text: i18n.tr("Yes, please.")
1285+// color: UbuntuColors.orange
1286+// objectName: "dialogNGButtonYes"
1287+// onClicked: {
1288+// optionsKeeper.setUseGoogleSearch(false)
1289+// PopupUtils.close(dialogNG)
1290+// }
1291+// }
1292+
1293+// Button {
1294+// text: i18n.tr("No, thanks.")
1295+// objectName: "dialogNGButtonNo"
1296+// onClicked: PopupUtils.close(dialogNG)
1297+// }
1298+// }
1299+// } // Component
1300
1301 /* -------------------------- Connections ---------------------------- */
1302
1303
1304=== modified file 'shorts/qml/utils/databasemodule_v2.js'
1305--- shorts/qml/utils/databasemodule_v2.js 2016-01-10 09:04:00 +0000
1306+++ shorts/qml/utils/databasemodule_v2.js 2016-03-18 09:56:42 +0000
1307@@ -40,9 +40,9 @@
1308 dbResult = tx.executeSql("alter table article add author text")
1309 console.log("Database updated: ", JSON.stringify(dbResult))
1310 })
1311- dbParams.newDbVersion = 1.1
1312- case 1.2:
1313- dbParams.newDbVersion = 1.2
1314+ dbParams.newDbVersion = "1.1"
1315+ case "1.2":
1316+ dbParams.newDbVersion = "1.2"
1317 }
1318
1319 var tagCount = 0
1320
1321=== added file 'shorts/qml/utils/xml2json.js'
1322--- shorts/qml/utils/xml2json.js 1970-01-01 00:00:00 +0000
1323+++ shorts/qml/utils/xml2json.js 2016-03-18 09:56:42 +0000
1324@@ -0,0 +1,242 @@
1325+/* Copyright 2015 William Summers, MetaTribal LLC
1326+ * adapted from https://developer.mozilla.org/en-US/docs/JXON
1327+ *
1328+ * Licensed under the MIT License, Version 2.0 (the "License");
1329+ * you may not use this file except in compliance with the License.
1330+ * You may obtain a copy of the License at
1331+ *
1332+ * https://opensource.org/licenses/MIT
1333+ *
1334+ * Unless required by applicable law or agreed to in writing, software
1335+ * distributed under the License is distributed on an "AS IS" BASIS,
1336+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1337+ * See the License for the specific language governing permissions and
1338+ * limitations under the License.
1339+ */
1340+/**
1341+ * @author William Summers
1342+ *
1343+ */
1344+
1345+var xmlToJSON = (function () {
1346+
1347+ this.version = "1.3";
1348+
1349+ var options = { // set up the default options
1350+ mergeCDATA: true, // extract cdata and merge with text
1351+ grokAttr: true, // convert truthy attributes to boolean, etc
1352+ grokText: true, // convert truthy text/attr to boolean, etc
1353+ normalize: true, // collapse multiple spaces to single space
1354+ xmlns: true, // include namespaces as attribute in output
1355+ namespaceKey: '_ns', // tag name for namespace objects
1356+ textKey: '_text', // tag name for text nodes
1357+ valueKey: '_value', // tag name for attribute values
1358+ attrKey: '_attr', // tag for attr groups
1359+ cdataKey: '_cdata', // tag for cdata nodes (ignored if mergeCDATA is true)
1360+ attrsAsObject: true, // if false, key is used as prefix to name, set prefix to '' to merge children and attrs.
1361+ stripAttrPrefix: true, // remove namespace prefixes from attributes
1362+ stripElemPrefix: true, // for elements of same name in diff namespaces, you can enable namespaces and access the nskey property
1363+ childrenAsArray: true // force children into arrays
1364+ };
1365+
1366+ var prefixMatch = new RegExp(/(?!xmlns)^.*:/);
1367+ var trimMatch = new RegExp(/^\s+|\s+$/g);
1368+
1369+ this.grokType = function (sValue) {
1370+ if (/^\s*$/.test(sValue)) {
1371+ return null;
1372+ }
1373+ if (/^(?:true|false)$/i.test(sValue)) {
1374+ return sValue.toLowerCase() === "true";
1375+ }
1376+ if (isFinite(sValue)) {
1377+ return parseFloat(sValue);
1378+ }
1379+ return sValue;
1380+ };
1381+
1382+ this.parseString = function (xmlString, opt) {
1383+ return this.parseXML(this.stringToXML(xmlString), opt);
1384+ }
1385+
1386+ this.parseXML = function (oXMLParent, opt) {
1387+
1388+ // initialize options
1389+ for (var key in opt) {
1390+ options[key] = opt[key];
1391+ }
1392+
1393+ var vResult = {},
1394+ nLength = 0,
1395+ sCollectedTxt = "";
1396+
1397+ // parse namespace information
1398+ if (options.xmlns && oXMLParent.namespaceURI) {
1399+ vResult[options.namespaceKey] = oXMLParent.namespaceURI;
1400+ }
1401+
1402+ // parse attributes
1403+ // using attributes property instead of hasAttributes method to support older browsers
1404+ if (oXMLParent.attributes && oXMLParent.attributes.length > 0) {
1405+ var vAttribs = {};
1406+
1407+ for (nLength; nLength < oXMLParent.attributes.length; nLength++) {
1408+ var oAttrib = oXMLParent.attributes.item(nLength);
1409+ vContent = {};
1410+ var attribName = '';
1411+
1412+ if (options.stripAttrPrefix) {
1413+ attribName = oAttrib.name.replace(prefixMatch, '');
1414+
1415+ } else {
1416+ attribName = oAttrib.name;
1417+ }
1418+
1419+ if (options.grokAttr) {
1420+ vContent[options.valueKey] = this.grokType(oAttrib.value.replace(trimMatch, ''));
1421+ } else {
1422+ vContent[options.valueKey] = oAttrib.value.replace(trimMatch, '');
1423+ }
1424+
1425+ if (options.xmlns && oAttrib.namespaceURI) {
1426+ vContent[options.namespaceKey] = oAttrib.namespaceURI;
1427+ }
1428+
1429+ if (options.attrsAsObject) { // attributes with same local name must enable prefixes
1430+ vAttribs[attribName] = vContent;
1431+ } else {
1432+ vResult[options.attrKey + attribName] = vContent;
1433+ }
1434+ }
1435+
1436+ if (options.attrsAsObject) {
1437+ vResult[options.attrKey] = vAttribs;
1438+ } else {}
1439+ }
1440+
1441+ // iterate over the children
1442+ if (oXMLParent.hasChildNodes()) {
1443+ for (var oNode, sProp, vContent, nItem = 0; nItem < oXMLParent.childNodes.length; nItem++) {
1444+ oNode = oXMLParent.childNodes.item(nItem);
1445+
1446+ if (oNode.nodeType === 4) {
1447+ if (options.mergeCDATA) {
1448+ sCollectedTxt += oNode.nodeValue;
1449+ } else {
1450+ if (vResult.hasOwnProperty(options.cdataKey)) {
1451+ if (vResult[options.cdataKey].constructor !== Array) {
1452+ vResult[options.cdataKey] = [vResult[options.cdataKey]];
1453+ }
1454+ vResult[options.cdataKey].push(oNode.nodeValue);
1455+
1456+ } else {
1457+ if (options.childrenAsArray) {
1458+ vResult[options.cdataKey] = [];
1459+ vResult[options.cdataKey].push(oNode.nodeValue);
1460+ } else {
1461+ vResult[options.cdataKey] = oNode.nodeValue;
1462+ }
1463+ }
1464+ }
1465+ } /* nodeType is "CDATASection" (4) */
1466+ else if (oNode.nodeType === 3) {
1467+ sCollectedTxt += oNode.nodeValue;
1468+ } /* nodeType is "Text" (3) */
1469+ else if (oNode.nodeType === 1) { /* nodeType is "Element" (1) */
1470+
1471+ if (nLength === 0) {
1472+ vResult = {};
1473+ }
1474+
1475+ // using nodeName to support browser (IE) implementation with no 'localName' property
1476+ if (options.stripElemPrefix) {
1477+ sProp = oNode.nodeName.replace(prefixMatch, '');
1478+ } else {
1479+ sProp = oNode.nodeName;
1480+ }
1481+
1482+ vContent = xmlToJSON.parseXML(oNode);
1483+
1484+ if (vResult.hasOwnProperty(sProp)) {
1485+ if (vResult[sProp].constructor !== Array) {
1486+ vResult[sProp] = [vResult[sProp]];
1487+ }
1488+ vResult[sProp].push(vContent);
1489+
1490+ } else {
1491+ if (options.childrenAsArray) {
1492+ vResult[sProp] = [];
1493+ vResult[sProp].push(vContent);
1494+ } else {
1495+ vResult[sProp] = vContent;
1496+ }
1497+ nLength++;
1498+ }
1499+ }
1500+ }
1501+ } else if (!sCollectedTxt) { // no children and no text, return null
1502+ if (options.childrenAsArray) {
1503+ vResult[options.textKey] = [];
1504+ vResult[options.textKey].push(null);
1505+ } else {
1506+ vResult[options.textKey] = null;
1507+ }
1508+ }
1509+
1510+ if (sCollectedTxt) {
1511+ if (options.grokText) {
1512+ var value = this.grokType(sCollectedTxt.replace(trimMatch, ''));
1513+ if (value !== null && value !== undefined) {
1514+ vResult[options.textKey] = value;
1515+ }
1516+ } else if (options.normalize) {
1517+ vResult[options.textKey] = sCollectedTxt.replace(trimMatch, '').replace(/\s+/g, " ");
1518+ } else {
1519+ vResult[options.textKey] = sCollectedTxt.replace(trimMatch, '');
1520+ }
1521+ }
1522+
1523+ return vResult;
1524+ }
1525+
1526+
1527+ // Convert xmlDocument to a string
1528+ // Returns null on failure
1529+ this.xmlToString = function (xmlDoc) {
1530+ try {
1531+ var xmlString = xmlDoc.xml ? xmlDoc.xml : (new XMLSerializer()).serializeToString(xmlDoc);
1532+ return xmlString;
1533+ } catch (err) {
1534+ return null;
1535+ }
1536+ }
1537+
1538+ // Convert a string to XML Node Structure
1539+ // Returns null on failure
1540+ this.stringToXML = function (xmlString) {
1541+ try {
1542+ var xmlDoc = null;
1543+
1544+ if (window.DOMParser) {
1545+
1546+ var parser = new DOMParser();
1547+ xmlDoc = parser.parseFromString(xmlString, "text/xml");
1548+
1549+ return xmlDoc;
1550+ } else {
1551+ xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
1552+ xmlDoc.async = false;
1553+ xmlDoc.loadXML(xmlString);
1554+
1555+ return xmlDoc;
1556+ }
1557+ } catch (e) {
1558+ return null;
1559+ }
1560+ }
1561+
1562+ return this;
1563+}).call({});
1564+
1565+if (typeof module != "undefined" && module !== null && module.exports) module.exports = xmlToJSON;
1566+else if (typeof define === "function" && define.amd) define(function() {return xmlToJSON});
1567
1568=== modified file 'shorts/shorts.pro'
1569--- shorts/shorts.pro 2015-12-03 16:01:09 +0000
1570+++ shorts/shorts.pro 2016-03-18 09:56:42 +0000
1571@@ -7,7 +7,7 @@
1572
1573 SOURCES += main.cpp \
1574 CachingNetworkManagerFactory.cpp \
1575- xml2json/utilities.cpp
1576+ utilities.cpp
1577
1578 RESOURCES += shorts.qrc
1579
1580@@ -65,7 +65,7 @@
1581
1582 HEADERS += \
1583 CachingNetworkManagerFactory.h \
1584- xml2json/utilities.h \
1585+ utilities.h \
1586 xml2json/rapidjson/error/en.h \
1587 xml2json/rapidjson/error/error.h \
1588 xml2json/rapidjson/internal/biginteger.h \
1589
1590=== modified file 'shorts/shorts.qrc'
1591--- shorts/shorts.qrc 2016-01-10 09:04:00 +0000
1592+++ shorts/shorts.qrc 2016-03-18 09:56:42 +0000
1593@@ -39,6 +39,14 @@
1594 <file>qml/content/OpmlParser.qml</file>
1595 <file>qml/content/ImportFeeds.qml</file>
1596 <file>qml/content/ContentPickerDialog.qml</file>
1597+ <file>qml/utils/xml2json.js</file>
1598+ <file>qml/pages/PageHelp.qml</file>
1599+ <file>qml/icons/help1.png</file>
1600+ <file>qml/icons/help2.png</file>
1601+ <file>qml/icons/help3.png</file>
1602+ <file>qml/icons/shorts.png</file>
1603+ <file>qml/pages/PageInfo.qml</file>
1604+ <file>qml/components/SettingsItem.qml</file>
1605 </qresource>
1606 <qresource prefix="/img">
1607 <file>qml/icons/add.svg</file>
1608
1609=== added file 'shorts/utilities.cpp'
1610--- shorts/utilities.cpp 1970-01-01 00:00:00 +0000
1611+++ shorts/utilities.cpp 2016-03-18 09:56:42 +0000
1612@@ -0,0 +1,68 @@
1613+#include "utilities.h"
1614+#include "xml2json/xml2json.hpp"
1615+
1616+Utilities::Utilities(QObject *parent) :
1617+ QObject(parent)
1618+{
1619+// qDebug() << "path: " << QDir::currentPath() ;
1620+// QFile xmlFile("xml");
1621+// xmlFile.open(QIODevice::ReadOnly | QIODevice::Text);
1622+
1623+// qDebug() << "json: " << xmlToJson(QString(xmlFile.readAll())).size();
1624+}
1625+
1626+QJsonObject Utilities::xmlToJson(const QString &xml)
1627+{
1628+ QByteArray ba = xml.toLocal8Bit();
1629+ char* ch = ba.data();
1630+ std::string json = "";
1631+ try
1632+ {
1633+ json = xml2json(ch);
1634+ }
1635+ catch (char* err)
1636+ {
1637+ Q_UNUSED(err);
1638+ json = "";
1639+ }
1640+
1641+// qDebug() << "json: " << QString::fromStdString(json) ;
1642+ return QJsonDocument::fromJson(QString::fromStdString(json).toLocal8Bit()).object();
1643+}
1644+
1645+QStringList Utilities::htmlGetImg(const QString &html)
1646+{
1647+ QRegExp imgTagRegex("\\<img[^\\>]*src\\s*=\\s*\"([^\"]*)\"[^\\>]*\\>", Qt::CaseInsensitive);
1648+ imgTagRegex.setMinimal(true);
1649+ QStringList urlmatches;
1650+ QStringList imgmatches;
1651+ int offset = 0;
1652+ while( (offset = imgTagRegex.indexIn(html, offset)) != -1)
1653+ {
1654+ offset += imgTagRegex.matchedLength();
1655+ imgmatches.append(imgTagRegex.cap(0)); // Should hold complete img tag
1656+ urlmatches.append(imgTagRegex.cap(1)); // Should hold only src property
1657+ }
1658+ return urlmatches;
1659+}
1660+
1661+QString Utilities::getSetting(const QString &key)
1662+{
1663+ QSettings settings;
1664+ return settings.value(key).toString();
1665+}
1666+
1667+void Utilities::setSetting(const QString &key, const QString &value)
1668+{
1669+ QSettings settings;
1670+ settings.setValue(key, value);
1671+}
1672+
1673+// QJsonObject Utilities::test()
1674+// {
1675+// QFile xmlFile("xml");
1676+// xmlFile.open(QIODevice::ReadOnly | QIODevice::Text);
1677+//
1678+// QJsonObject obj = xmlToJson(QString(xmlFile.readAll()));
1679+// return obj;
1680+// }
1681
1682=== added file 'shorts/utilities.h'
1683--- shorts/utilities.h 1970-01-01 00:00:00 +0000
1684+++ shorts/utilities.h 2016-03-18 09:56:42 +0000
1685@@ -0,0 +1,28 @@
1686+#ifndef UTILITIES_H
1687+#define UTILITIES_H
1688+
1689+#include <QtCore>
1690+
1691+class Utilities : public QObject
1692+{
1693+ Q_OBJECT
1694+public:
1695+ explicit Utilities(QObject *parent = 0);
1696+
1697+ Q_INVOKABLE QJsonObject xmlToJson(const QString &xml);
1698+ Q_INVOKABLE QStringList htmlGetImg(const QString &html);
1699+
1700+ // get & set settings' values
1701+ Q_INVOKABLE QString getSetting(const QString &key);
1702+ Q_INVOKABLE void setSetting(const QString &key, const QString &value);
1703+
1704+ // test only
1705+// Q_INVOKABLE QJsonObject test();
1706+
1707+signals:
1708+
1709+public slots:
1710+
1711+};
1712+
1713+#endif // UTILITIES_H
1714
1715=== modified file 'shorts/xml2json/rapidjson/allocators.h'
1716--- shorts/xml2json/rapidjson/allocators.h 2015-12-02 17:03:41 +0000
1717+++ shorts/xml2json/rapidjson/allocators.h 2016-03-18 09:56:42 +0000
1718@@ -1,22 +1,16 @@
1719-// Copyright (C) 2011 Milo Yip
1720-//
1721-// Permission is hereby granted, free of charge, to any person obtaining a copy
1722-// of this software and associated documentation files (the "Software"), to deal
1723-// in the Software without restriction, including without limitation the rights
1724-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1725-// copies of the Software, and to permit persons to whom the Software is
1726-// furnished to do so, subject to the following conditions:
1727-//
1728-// The above copyright notice and this permission notice shall be included in
1729-// all copies or substantial portions of the Software.
1730-//
1731-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1732-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1733-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1734-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1735-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1736-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1737-// THE SOFTWARE.
1738+// Tencent is pleased to support the open source community by making RapidJSON available.
1739+//
1740+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
1741+//
1742+// Licensed under the MIT License (the "License"); you may not use this file except
1743+// in compliance with the License. You may obtain a copy of the License at
1744+//
1745+// http://opensource.org/licenses/MIT
1746+//
1747+// Unless required by applicable law or agreed to in writing, software distributed
1748+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
1749+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1750+// specific language governing permissions and limitations under the License.
1751
1752 #ifndef RAPIDJSON_ALLOCATORS_H_
1753 #define RAPIDJSON_ALLOCATORS_H_
1754@@ -68,8 +62,20 @@
1755 class CrtAllocator {
1756 public:
1757 static const bool kNeedFree = true;
1758- void* Malloc(size_t size) { return std::malloc(size); }
1759- void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; return std::realloc(originalPtr, newSize); }
1760+ void* Malloc(size_t size) {
1761+ if (size) // behavior of malloc(0) is implementation defined.
1762+ return std::malloc(size);
1763+ else
1764+ return NULL; // standardize to returning NULL.
1765+ }
1766+ void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) {
1767+ (void)originalSize;
1768+ if (newSize == 0) {
1769+ std::free(originalPtr);
1770+ return NULL;
1771+ }
1772+ return std::realloc(originalPtr, newSize);
1773+ }
1774 static void Free(void *ptr) { std::free(ptr); }
1775 };
1776
1777@@ -137,11 +143,13 @@
1778
1779 //! Deallocates all memory chunks, excluding the user-supplied buffer.
1780 void Clear() {
1781- while(chunkHead_ != 0 && chunkHead_ != userBuffer_) {
1782+ while (chunkHead_ && chunkHead_ != userBuffer_) {
1783 ChunkHeader* next = chunkHead_->next;
1784 baseAllocator_->Free(chunkHead_);
1785 chunkHead_ = next;
1786 }
1787+ if (chunkHead_ && chunkHead_ == userBuffer_)
1788+ chunkHead_->size = 0; // Clear user buffer
1789 }
1790
1791 //! Computes the total capacity of allocated memory chunks.
1792@@ -166,11 +174,14 @@
1793
1794 //! Allocates a memory block. (concept Allocator)
1795 void* Malloc(size_t size) {
1796+ if (!size)
1797+ return NULL;
1798+
1799 size = RAPIDJSON_ALIGN(size);
1800 if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity)
1801 AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size);
1802
1803- void *buffer = reinterpret_cast<char *>(chunkHead_ + 1) + chunkHead_->size;
1804+ void *buffer = reinterpret_cast<char *>(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size;
1805 chunkHead_->size += size;
1806 return buffer;
1807 }
1808@@ -180,12 +191,15 @@
1809 if (originalPtr == 0)
1810 return Malloc(newSize);
1811
1812+ if (newSize == 0)
1813+ return NULL;
1814+
1815 // Do not shrink if new size is smaller than original
1816 if (originalSize >= newSize)
1817 return originalPtr;
1818
1819 // Simply expand it if it is the last allocation and there is sufficient space
1820- if (originalPtr == (char *)(chunkHead_ + 1) + chunkHead_->size - originalSize) {
1821+ if (originalPtr == reinterpret_cast<char *>(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size - originalSize) {
1822 size_t increment = static_cast<size_t>(newSize - originalSize);
1823 increment = RAPIDJSON_ALIGN(increment);
1824 if (chunkHead_->size + increment <= chunkHead_->capacity) {
1825@@ -197,7 +211,9 @@
1826 // Realloc process: allocate and copy memory, do not free original buffer.
1827 void* newBuffer = Malloc(newSize);
1828 RAPIDJSON_ASSERT(newBuffer != 0); // Do not handle out-of-memory explicitly.
1829- return std::memcpy(newBuffer, originalPtr, originalSize);
1830+ if (originalSize)
1831+ std::memcpy(newBuffer, originalPtr, originalSize);
1832+ return newBuffer;
1833 }
1834
1835 //! Frees a memory block (concept Allocator)
1836@@ -215,7 +231,7 @@
1837 void AddChunk(size_t capacity) {
1838 if (!baseAllocator_)
1839 ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator());
1840- ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(baseAllocator_->Malloc(sizeof(ChunkHeader) + capacity));
1841+ ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity));
1842 chunk->capacity = capacity;
1843 chunk->size = 0;
1844 chunk->next = chunkHead_;
1845
1846=== modified file 'shorts/xml2json/rapidjson/document.h'
1847--- shorts/xml2json/rapidjson/document.h 2015-12-02 17:03:41 +0000
1848+++ shorts/xml2json/rapidjson/document.h 2016-03-18 09:56:42 +0000
1849@@ -1,22 +1,16 @@
1850-// Copyright (C) 2011 Milo Yip
1851-//
1852-// Permission is hereby granted, free of charge, to any person obtaining a copy
1853-// of this software and associated documentation files (the "Software"), to deal
1854-// in the Software without restriction, including without limitation the rights
1855-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1856-// copies of the Software, and to permit persons to whom the Software is
1857-// furnished to do so, subject to the following conditions:
1858-//
1859-// The above copyright notice and this permission notice shall be included in
1860-// all copies or substantial portions of the Software.
1861-//
1862-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1863-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1864-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1865-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1866-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1867-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1868-// THE SOFTWARE.
1869+// Tencent is pleased to support the open source community by making RapidJSON available.
1870+//
1871+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
1872+//
1873+// Licensed under the MIT License (the "License"); you may not use this file except
1874+// in compliance with the License. You may obtain a copy of the License at
1875+//
1876+// http://opensource.org/licenses/MIT
1877+//
1878+// Unless required by applicable law or agreed to in writing, software distributed
1879+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
1880+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1881+// specific language governing permissions and limitations under the License.
1882
1883 #ifndef RAPIDJSON_DOCUMENT_H_
1884 #define RAPIDJSON_DOCUMENT_H_
1885@@ -31,33 +25,19 @@
1886 #ifdef _MSC_VER
1887 RAPIDJSON_DIAG_PUSH
1888 RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
1889-#elif defined(__GNUC__)
1890+#endif
1891+
1892+#ifdef __clang__
1893+RAPIDJSON_DIAG_PUSH
1894+RAPIDJSON_DIAG_OFF(padded)
1895+RAPIDJSON_DIAG_OFF(switch-enum)
1896+#endif
1897+
1898+#ifdef __GNUC__
1899 RAPIDJSON_DIAG_PUSH
1900 RAPIDJSON_DIAG_OFF(effc++)
1901 #endif
1902
1903-///////////////////////////////////////////////////////////////////////////////
1904-// RAPIDJSON_HAS_STDSTRING
1905-
1906-#ifndef RAPIDJSON_HAS_STDSTRING
1907-#ifdef RAPIDJSON_DOXYGEN_RUNNING
1908-#define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation
1909-#else
1910-#define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default
1911-#endif
1912-/*! \def RAPIDJSON_HAS_STDSTRING
1913- \ingroup RAPIDJSON_CONFIG
1914- \brief Enable RapidJSON support for \c std::string
1915-
1916- By defining this preprocessor symbol to \c 1, several convenience functions for using
1917- \ref rapidjson::GenericValue with \c std::string are enabled, especially
1918- for construction and comparison.
1919-
1920- \hideinitializer
1921-*/
1922-#include <string>
1923-#endif // RAPIDJSON_HAS_STDSTRING
1924-
1925 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
1926 #include <iterator> // std::iterator, std::random_access_iterator_tag
1927 #endif
1928@@ -72,6 +52,9 @@
1929 template <typename Encoding, typename Allocator>
1930 class GenericValue;
1931
1932+template <typename Encoding, typename Allocator, typename StackAllocator>
1933+class GenericDocument;
1934+
1935 //! Name-value pair in a JSON object value.
1936 /*!
1937 This class was internal to GenericValue. It used to be a inner struct.
1938@@ -260,6 +243,7 @@
1939 typedef CharType Ch; //!< character type of the string
1940
1941 //! Create string reference from \c const character array
1942+#ifndef __clang__ // -Wdocumentation
1943 /*!
1944 This constructor implicitly creates a constant string reference from
1945 a \c const character array. It has better performance than
1946@@ -282,11 +266,13 @@
1947 In such cases, the referenced string should be \b copied to the
1948 GenericValue instead.
1949 */
1950+#endif
1951 template<SizeType N>
1952 GenericStringRef(const CharType (&str)[N]) RAPIDJSON_NOEXCEPT
1953 : s(str), length(N-1) {}
1954
1955 //! Explicitly create string reference from \c const character pointer
1956+#ifndef __clang__ // -Wdocumentation
1957 /*!
1958 This constructor can be used to \b explicitly create a reference to
1959 a constant string pointer.
1960@@ -305,16 +291,19 @@
1961 In such cases, the referenced string should be \b copied to the
1962 GenericValue instead.
1963 */
1964+#endif
1965 explicit GenericStringRef(const CharType* str)
1966 : s(str), length(internal::StrLen(str)){ RAPIDJSON_ASSERT(s != NULL); }
1967
1968 //! Create constant string reference from pointer and length
1969+#ifndef __clang__ // -Wdocumentation
1970 /*! \param str constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue
1971 \param len length of the string, excluding the trailing NULL terminator
1972
1973 \post \ref s == str && \ref length == len
1974 \note Constant complexity.
1975 */
1976+#endif
1977 GenericStringRef(const CharType* str, SizeType len)
1978 : s(str), length(len) { RAPIDJSON_ASSERT(s != NULL); }
1979
1980@@ -430,6 +419,7 @@
1981 typedef typename GenericMemberIterator<true,Encoding,Allocator>::Iterator ConstMemberIterator; //!< Constant member iterator for iterating in object.
1982 typedef GenericValue* ValueIterator; //!< Value iterator for iterating in array.
1983 typedef const GenericValue* ConstValueIterator; //!< Constant value iterator for iterating in array.
1984+ typedef GenericValue<Encoding, Allocator> ValueType; //!< Value type of itself.
1985
1986 //!@name Constructors and destructor.
1987 //@{
1988@@ -448,6 +438,16 @@
1989 //! Copy constructor is not permitted.
1990 GenericValue(const GenericValue& rhs);
1991
1992+#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1993+ //! Moving from a GenericDocument is not permitted.
1994+ template <typename StackAllocator>
1995+ GenericValue(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
1996+
1997+ //! Move assignment from a GenericDocument is not permitted.
1998+ template <typename StackAllocator>
1999+ GenericValue& operator=(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
2000+#endif
2001+
2002 public:
2003
2004 //! Constructor with JSON value type.
2005@@ -643,7 +643,7 @@
2006 */
2007 template <typename SourceAllocator>
2008 GenericValue& CopyFrom(const GenericValue<Encoding, SourceAllocator>& rhs, Allocator& allocator) {
2009- RAPIDJSON_ASSERT((void*)this != (void const*)&rhs);
2010+ RAPIDJSON_ASSERT(static_cast<void*>(this) != static_cast<void const*>(&rhs));
2011 this->~GenericValue();
2012 new (this) GenericValue(rhs, allocator);
2013 return *this;
2014@@ -662,6 +662,20 @@
2015 return *this;
2016 }
2017
2018+ //! free-standing swap function helper
2019+ /*!
2020+ Helper function to enable support for common swap implementation pattern based on \c std::swap:
2021+ \code
2022+ void swap(MyClass& a, MyClass& b) {
2023+ using std::swap;
2024+ swap(a.value, b.value);
2025+ // ...
2026+ }
2027+ \endcode
2028+ \see Swap()
2029+ */
2030+ friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
2031+
2032 //! Prepare Value for move semantics
2033 /*! \return *this */
2034 GenericValue& Move() RAPIDJSON_NOEXCEPT { return *this; }
2035@@ -703,12 +717,15 @@
2036 return StringEqual(rhs);
2037
2038 case kNumberType:
2039- if (IsDouble() || rhs.IsDouble())
2040- return GetDouble() == rhs.GetDouble(); // May convert one operand from integer to double.
2041+ if (IsDouble() || rhs.IsDouble()) {
2042+ double a = GetDouble(); // May convert from integer to double.
2043+ double b = rhs.GetDouble(); // Ditto
2044+ return a >= b && a <= b; // Prevent -Wfloat-equal
2045+ }
2046 else
2047 return data_.n.u64 == rhs.data_.n.u64;
2048
2049- default: // kTrueType, kFalseType, kNullType
2050+ default:
2051 return true;
2052 }
2053 }
2054@@ -836,13 +853,25 @@
2055 return member->value;
2056 else {
2057 RAPIDJSON_ASSERT(false); // see above note
2058- static GenericValue NullValue;
2059- return NullValue;
2060+
2061+ // This will generate -Wexit-time-destructors in clang
2062+ // static GenericValue NullValue;
2063+ // return NullValue;
2064+
2065+ // Use static buffer and placement-new to prevent destruction
2066+ static char buffer[sizeof(GenericValue)];
2067+ return *new (buffer) GenericValue();
2068 }
2069 }
2070 template <typename SourceAllocator>
2071 const GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this)[name]; }
2072
2073+#if RAPIDJSON_HAS_STDSTRING
2074+ //! Get a value from an object associated with name (string object).
2075+ GenericValue& operator[](const std::basic_string<Ch>& name) { return (*this)[GenericValue(StringRef(name))]; }
2076+ const GenericValue& operator[](const std::basic_string<Ch>& name) const { return (*this)[GenericValue(StringRef(name))]; }
2077+#endif
2078+
2079 //! Const member iterator
2080 /*! \pre IsObject() == true */
2081 ConstMemberIterator MemberBegin() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(data_.o.members); }
2082@@ -866,6 +895,18 @@
2083 */
2084 bool HasMember(const Ch* name) const { return FindMember(name) != MemberEnd(); }
2085
2086+#if RAPIDJSON_HAS_STDSTRING
2087+ //! Check whether a member exists in the object with string object.
2088+ /*!
2089+ \param name Member name to be searched.
2090+ \pre IsObject() == true
2091+ \return Whether a member with that name exists.
2092+ \note It is better to use FindMember() directly if you need the obtain the value as well.
2093+ \note Linear time complexity.
2094+ */
2095+ bool HasMember(const std::basic_string<Ch>& name) const { return FindMember(name) != MemberEnd(); }
2096+#endif
2097+
2098 //! Check whether a member exists in the object with GenericValue name.
2099 /*!
2100 This version is faster because it does not need a StrLen(). It can also handle string with null character.
2101@@ -922,6 +963,18 @@
2102 }
2103 template <typename SourceAllocator> ConstMemberIterator FindMember(const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
2104
2105+#if RAPIDJSON_HAS_STDSTRING
2106+ //! Find member by string object name.
2107+ /*!
2108+ \param name Member name to be searched.
2109+ \pre IsObject() == true
2110+ \return Iterator to member, if it exists.
2111+ Otherwise returns \ref MemberEnd().
2112+ */
2113+ MemberIterator FindMember(const std::basic_string<Ch>& name) { return FindMember(StringRef(name)); }
2114+ ConstMemberIterator FindMember(const std::basic_string<Ch>& name) const { return FindMember(StringRef(name)); }
2115+#endif
2116+
2117 //! Add a member (name-value pair) to the object.
2118 /*! \param name A string value as name of member.
2119 \param value Value of any type.
2120@@ -968,6 +1021,22 @@
2121 return AddMember(name, v, allocator);
2122 }
2123
2124+#if RAPIDJSON_HAS_STDSTRING
2125+ //! Add a string object as member (name-value pair) to the object.
2126+ /*! \param name A string value as name of member.
2127+ \param value constant string reference as value of member.
2128+ \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
2129+ \return The value itself for fluent API.
2130+ \pre IsObject()
2131+ \note This overload is needed to avoid clashes with the generic primitive type AddMember(GenericValue&,T,Allocator&) overload below.
2132+ \note Amortized Constant time complexity.
2133+ */
2134+ GenericValue& AddMember(GenericValue& name, std::basic_string<Ch>& value, Allocator& allocator) {
2135+ GenericValue v(value, allocator);
2136+ return AddMember(name, v, allocator);
2137+ }
2138+#endif
2139+
2140 //! Add any primitive value as member (name-value pair) to the object.
2141 /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t
2142 \param name A string value as name of member.
2143@@ -1086,6 +1155,10 @@
2144 return RemoveMember(n);
2145 }
2146
2147+#if RAPIDJSON_HAS_STDSTRING
2148+ bool RemoveMember(const std::basic_string<Ch>& name) { return RemoveMember(GenericValue(StringRef(name))); }
2149+#endif
2150+
2151 template <typename SourceAllocator>
2152 bool RemoveMember(const GenericValue<Encoding, SourceAllocator>& name) {
2153 MemberIterator m = FindMember(name);
2154@@ -1157,11 +1230,36 @@
2155 MemberIterator pos = MemberBegin() + (first - MemberBegin());
2156 for (MemberIterator itr = pos; itr != last; ++itr)
2157 itr->~Member();
2158- std::memmove(&*pos, &*last, (MemberEnd() - last) * sizeof(Member));
2159- data_.o.size -= (last - first);
2160+ std::memmove(&*pos, &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
2161+ data_.o.size -= static_cast<SizeType>(last - first);
2162 return pos;
2163 }
2164
2165+ //! Erase a member in object by its name.
2166+ /*! \param name Name of member to be removed.
2167+ \return Whether the member existed.
2168+ \note Linear time complexity.
2169+ */
2170+ bool EraseMember(const Ch* name) {
2171+ GenericValue n(StringRef(name));
2172+ return EraseMember(n);
2173+ }
2174+
2175+#if RAPIDJSON_HAS_STDSTRING
2176+ bool EraseMember(const std::basic_string<Ch>& name) { return EraseMember(GenericValue(StringRef(name))); }
2177+#endif
2178+
2179+ template <typename SourceAllocator>
2180+ bool EraseMember(const GenericValue<Encoding, SourceAllocator>& name) {
2181+ MemberIterator m = FindMember(name);
2182+ if (m != MemberEnd()) {
2183+ EraseMember(m);
2184+ return true;
2185+ }
2186+ else
2187+ return false;
2188+ }
2189+
2190 //@}
2191
2192 //!@name Array
2193@@ -1225,7 +1323,7 @@
2194 GenericValue& Reserve(SizeType newCapacity, Allocator &allocator) {
2195 RAPIDJSON_ASSERT(IsArray());
2196 if (newCapacity > data_.a.capacity) {
2197- data_.a.elements = (GenericValue*)allocator.Realloc(data_.a.elements, data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue));
2198+ data_.a.elements = static_cast<GenericValue*>(allocator.Realloc(data_.a.elements, data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue)));
2199 data_.a.capacity = newCapacity;
2200 }
2201 return *this;
2202@@ -1332,8 +1430,8 @@
2203 ValueIterator pos = Begin() + (first - Begin());
2204 for (ValueIterator itr = pos; itr != last; ++itr)
2205 itr->~GenericValue();
2206- std::memmove(pos, last, (End() - last) * sizeof(GenericValue));
2207- data_.a.size -= (last - first);
2208+ std::memmove(pos, last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
2209+ data_.a.size -= static_cast<SizeType>(last - first);
2210 return pos;
2211 }
2212
2213@@ -1352,8 +1450,8 @@
2214 if ((flags_ & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion.
2215 if ((flags_ & kIntFlag) != 0) return data_.n.i.i; // int -> double
2216 if ((flags_ & kUintFlag) != 0) return data_.n.u.u; // unsigned -> double
2217- if ((flags_ & kInt64Flag) != 0) return (double)data_.n.i64; // int64_t -> double (may lose precision)
2218- RAPIDJSON_ASSERT((flags_ & kUint64Flag) != 0); return (double)data_.n.u64; // uint64_t -> double (may lose precision)
2219+ if ((flags_ & kInt64Flag) != 0) return static_cast<double>(data_.n.i64); // int64_t -> double (may lose precision)
2220+ RAPIDJSON_ASSERT((flags_ & kUint64Flag) != 0); return static_cast<double>(data_.n.u64); // uint64_t -> double (may lose precision)
2221 }
2222
2223 GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; }
2224@@ -1417,7 +1515,7 @@
2225 \post IsString() == true && GetString() != s.data() && strcmp(GetString(),s.data() == 0 && GetStringLength() == s.size()
2226 \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING.
2227 */
2228- GenericValue& SetString(const std::basic_string<Ch>& s, Allocator& allocator) { return SetString(s.data(), s.size(), allocator); }
2229+ GenericValue& SetString(const std::basic_string<Ch>& s, Allocator& allocator) { return SetString(s.data(), SizeType(s.size()), allocator); }
2230 #endif
2231
2232 //@}
2233@@ -1459,17 +1557,14 @@
2234 case kStringType:
2235 return handler.String(GetString(), GetStringLength(), (flags_ & kCopyFlag) != 0);
2236
2237- case kNumberType:
2238+ default:
2239+ RAPIDJSON_ASSERT(GetType() == kNumberType);
2240 if (IsInt()) return handler.Int(data_.n.i.i);
2241 else if (IsUint()) return handler.Uint(data_.n.u.u);
2242 else if (IsInt64()) return handler.Int64(data_.n.i64);
2243 else if (IsUint64()) return handler.Uint64(data_.n.u64);
2244 else return handler.Double(data_.n.d);
2245-
2246- default:
2247- RAPIDJSON_ASSERT(false);
2248 }
2249- return false;
2250 }
2251
2252 private:
2253@@ -1528,9 +1623,9 @@
2254 enum { MaxChars = sizeof(String) / sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
2255 Ch str[MaxChars];
2256
2257- inline static bool Usable(SizeType len) { return (MaxSize >= len); }
2258- inline void SetLength(SizeType len) { str[LenPos] = (Ch)(MaxSize - len); }
2259- inline SizeType GetLength() const { return (SizeType)(MaxSize - str[LenPos]); }
2260+ inline static bool Usable(SizeType len) { return (MaxSize >= len); }
2261+ inline void SetLength(SizeType len) { str[LenPos] = static_cast<Ch>(MaxSize - len); }
2262+ inline SizeType GetLength() const { return static_cast<SizeType>(MaxSize - str[LenPos]); }
2263 }; // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
2264
2265 // By using proper binary layout, retrieval of different integer types do not need conversions.
2266@@ -1582,16 +1677,24 @@
2267 // Initialize this value as array with initial data, without calling destructor.
2268 void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) {
2269 flags_ = kArrayFlag;
2270- data_.a.elements = (GenericValue*)allocator.Malloc(count * sizeof(GenericValue));
2271- std::memcpy(data_.a.elements, values, count * sizeof(GenericValue));
2272+ if (count) {
2273+ data_.a.elements = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
2274+ std::memcpy(data_.a.elements, values, count * sizeof(GenericValue));
2275+ }
2276+ else
2277+ data_.a.elements = NULL;
2278 data_.a.size = data_.a.capacity = count;
2279 }
2280
2281 //! Initialize this value as object with initial data, without calling destructor.
2282 void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) {
2283 flags_ = kObjectFlag;
2284- data_.o.members = (Member*)allocator.Malloc(count * sizeof(Member));
2285- std::memcpy(data_.o.members, members, count * sizeof(Member));
2286+ if (count) {
2287+ data_.o.members = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
2288+ std::memcpy(data_.o.members, members, count * sizeof(Member));
2289+ }
2290+ else
2291+ data_.o.members = NULL;
2292 data_.o.size = data_.o.capacity = count;
2293 }
2294
2295@@ -1612,7 +1715,7 @@
2296 } else {
2297 flags_ = kCopyStringFlag;
2298 data_.s.length = s.length;
2299- str = (Ch *)allocator.Malloc((s.length + 1) * sizeof(Ch));
2300+ str = static_cast<Ch *>(allocator.Malloc((s.length + 1) * sizeof(Ch)));
2301 data_.s.str = str;
2302 }
2303 std::memcpy(str, s, s.length * sizeof(Ch));
2304@@ -1668,7 +1771,22 @@
2305 typedef Allocator AllocatorType; //!< Allocator type from template parameter.
2306
2307 //! Constructor
2308- /*! \param allocator Optional allocator for allocating memory.
2309+ /*! Creates an empty document of specified type.
2310+ \param type Mandatory type of object to create.
2311+ \param allocator Optional allocator for allocating memory.
2312+ \param stackCapacity Optional initial capacity of stack in bytes.
2313+ \param stackAllocator Optional allocator for allocating memory for stack.
2314+ */
2315+ explicit GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
2316+ GenericValue<Encoding, Allocator>(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2317+ {
2318+ if (!allocator_)
2319+ ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator());
2320+ }
2321+
2322+ //! Constructor
2323+ /*! Creates an empty document which type is Null.
2324+ \param allocator Optional allocator for allocating memory.
2325 \param stackCapacity Optional initial capacity of stack in bytes.
2326 \param stackAllocator Optional allocator for allocating memory for stack.
2327 */
2328@@ -1682,7 +1800,7 @@
2329 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2330 //! Move constructor in C++11
2331 GenericDocument(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2332- : ValueType(std::move(rhs)),
2333+ : ValueType(std::forward<ValueType>(rhs)), // explicit cast to avoid prohibited move from Document
2334 allocator_(rhs.allocator_),
2335 ownAllocator_(rhs.ownAllocator_),
2336 stack_(std::move(rhs.stack_)),
2337@@ -1722,6 +1840,35 @@
2338 }
2339 #endif
2340
2341+ //! Exchange the contents of this document with those of another.
2342+ /*!
2343+ \param rhs Another document.
2344+ \note Constant complexity.
2345+ \see GenericValue::Swap
2346+ */
2347+ GenericDocument& Swap(GenericDocument& rhs) RAPIDJSON_NOEXCEPT {
2348+ ValueType::Swap(rhs);
2349+ stack_.Swap(rhs.stack_);
2350+ internal::Swap(allocator_, rhs.allocator_);
2351+ internal::Swap(ownAllocator_, rhs.ownAllocator_);
2352+ internal::Swap(parseResult_, rhs.parseResult_);
2353+ return *this;
2354+ }
2355+
2356+ //! free-standing swap function helper
2357+ /*!
2358+ Helper function to enable support for common swap implementation pattern based on \c std::swap:
2359+ \code
2360+ void swap(MyClass& a, MyClass& b) {
2361+ using std::swap;
2362+ swap(a.doc, b.doc);
2363+ // ...
2364+ }
2365+ \endcode
2366+ \see Swap()
2367+ */
2368+ friend inline void swap(GenericDocument& a, GenericDocument& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
2369+
2370 //!@name Parse from stream
2371 //!@{
2372
2373@@ -1734,13 +1881,13 @@
2374 */
2375 template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
2376 GenericDocument& ParseStream(InputStream& is) {
2377- ValueType::SetNull(); // Remove existing root if exist
2378- GenericReader<SourceEncoding, Encoding, Allocator> reader(&GetAllocator());
2379+ GenericReader<SourceEncoding, Encoding, StackAllocator> reader(
2380+ stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2381 ClearStackOnExit scope(*this);
2382 parseResult_ = reader.template Parse<parseFlags>(is, *this);
2383 if (parseResult_) {
2384 RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2385- this->RawAssign(*stack_.template Pop<ValueType>(1)); // Add this-> to prevent issue 13.
2386+ ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2387 }
2388 return *this;
2389 }
2390@@ -1753,7 +1900,7 @@
2391 */
2392 template <unsigned parseFlags, typename InputStream>
2393 GenericDocument& ParseStream(InputStream& is) {
2394- return ParseStream<parseFlags,Encoding,InputStream>(is);
2395+ return ParseStream<parseFlags, Encoding, InputStream>(is);
2396 }
2397
2398 //! Parse JSON text from an input stream (with \ref kParseDefaultFlags)
2399@@ -1770,26 +1917,15 @@
2400 //!@name Parse in-place from mutable string
2401 //!@{
2402
2403- //! Parse JSON text from a mutable string (with Encoding conversion)
2404+ //! Parse JSON text from a mutable string
2405 /*! \tparam parseFlags Combination of \ref ParseFlag.
2406- \tparam SourceEncoding Transcoding from input Encoding
2407 \param str Mutable zero-terminated string to be parsed.
2408 \return The document itself for fluent API.
2409 */
2410- template <unsigned parseFlags, typename SourceEncoding>
2411+ template <unsigned parseFlags>
2412 GenericDocument& ParseInsitu(Ch* str) {
2413 GenericInsituStringStream<Encoding> s(str);
2414- return ParseStream<parseFlags | kParseInsituFlag, SourceEncoding>(s);
2415- }
2416-
2417- //! Parse JSON text from a mutable string
2418- /*! \tparam parseFlags Combination of \ref ParseFlag.
2419- \param str Mutable zero-terminated string to be parsed.
2420- \return The document itself for fluent API.
2421- */
2422- template <unsigned parseFlags>
2423- GenericDocument& ParseInsitu(Ch* str) {
2424- return ParseInsitu<parseFlags, Encoding>(str);
2425+ return ParseStream<parseFlags | kParseInsituFlag>(s);
2426 }
2427
2428 //! Parse JSON text from a mutable string (with \ref kParseDefaultFlags)
2429@@ -1797,7 +1933,7 @@
2430 \return The document itself for fluent API.
2431 */
2432 GenericDocument& ParseInsitu(Ch* str) {
2433- return ParseInsitu<kParseDefaultFlags, Encoding>(str);
2434+ return ParseInsitu<kParseDefaultFlags>(str);
2435 }
2436 //!@}
2437
2438@@ -1810,7 +1946,7 @@
2439 \param str Read-only zero-terminated string to be parsed.
2440 */
2441 template <unsigned parseFlags, typename SourceEncoding>
2442- GenericDocument& Parse(const Ch* str) {
2443+ GenericDocument& Parse(const typename SourceEncoding::Ch* str) {
2444 RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2445 GenericStringStream<SourceEncoding> s(str);
2446 return ParseStream<parseFlags, SourceEncoding>(s);
2447@@ -1845,10 +1981,26 @@
2448 //! Get the position of last parsing error in input, 0 otherwise.
2449 size_t GetErrorOffset() const { return parseResult_.Offset(); }
2450
2451+ //! Implicit conversion to get the last parse result
2452+#ifndef __clang // -Wdocumentation
2453+ /*! \return \ref ParseResult of the last parse operation
2454+
2455+ \code
2456+ Document doc;
2457+ ParseResult ok = doc.Parse(json);
2458+ if (!ok)
2459+ printf( "JSON parse error: %s (%u)\n", GetParseError_En(ok.Code()), ok.Offset());
2460+ \endcode
2461+ */
2462+#endif
2463+ operator ParseResult() const { return parseResult_; }
2464 //!@}
2465
2466 //! Get the allocator of this document.
2467- Allocator& GetAllocator() { return *allocator_; }
2468+ Allocator& GetAllocator() {
2469+ RAPIDJSON_ASSERT(allocator_);
2470+ return *allocator_;
2471+ }
2472
2473 //! Get the capacity of stack in bytes.
2474 size_t GetStackCapacity() const { return stack_.GetCapacity(); }
2475@@ -1891,7 +2043,7 @@
2476
2477 bool EndObject(SizeType memberCount) {
2478 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2479- stack_.template Top<ValueType>()->SetObjectRaw(members, (SizeType)memberCount, GetAllocator());
2480+ stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2481 return true;
2482 }
2483
2484@@ -1954,15 +2106,24 @@
2485 SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator);
2486 }
2487 break;
2488- default: // kNumberType, kTrueType, kFalseType, kNullType
2489+ default:
2490 flags_ = rhs.flags_;
2491 data_ = *reinterpret_cast<const Data*>(&rhs.data_);
2492+ break;
2493 }
2494 }
2495
2496 RAPIDJSON_NAMESPACE_END
2497
2498-#if defined(_MSC_VER) || defined(__GNUC__)
2499+#ifdef _MSC_VER
2500+RAPIDJSON_DIAG_POP
2501+#endif
2502+
2503+#ifdef __clang__
2504+RAPIDJSON_DIAG_POP
2505+#endif
2506+
2507+#ifdef __GNUC__
2508 RAPIDJSON_DIAG_POP
2509 #endif
2510
2511
2512=== modified file 'shorts/xml2json/rapidjson/encodedstream.h'
2513--- shorts/xml2json/rapidjson/encodedstream.h 2015-12-02 17:03:41 +0000
2514+++ shorts/xml2json/rapidjson/encodedstream.h 2016-03-18 09:56:42 +0000
2515@@ -1,22 +1,16 @@
2516-// Copyright (C) 2011 Milo Yip
2517-//
2518-// Permission is hereby granted, free of charge, to any person obtaining a copy
2519-// of this software and associated documentation files (the "Software"), to deal
2520-// in the Software without restriction, including without limitation the rights
2521-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2522-// copies of the Software, and to permit persons to whom the Software is
2523-// furnished to do so, subject to the following conditions:
2524-//
2525-// The above copyright notice and this permission notice shall be included in
2526-// all copies or substantial portions of the Software.
2527-//
2528-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2529-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2530-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2531-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2532-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2533-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2534-// THE SOFTWARE.
2535+// Tencent is pleased to support the open source community by making RapidJSON available.
2536+//
2537+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
2538+//
2539+// Licensed under the MIT License (the "License"); you may not use this file except
2540+// in compliance with the License. You may obtain a copy of the License at
2541+//
2542+// http://opensource.org/licenses/MIT
2543+//
2544+// Unless required by applicable law or agreed to in writing, software distributed
2545+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
2546+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
2547+// specific language governing permissions and limitations under the License.
2548
2549 #ifndef RAPIDJSON_ENCODEDSTREAM_H_
2550 #define RAPIDJSON_ENCODEDSTREAM_H_
2551@@ -28,6 +22,11 @@
2552 RAPIDJSON_DIAG_OFF(effc++)
2553 #endif
2554
2555+#ifdef __clang__
2556+RAPIDJSON_DIAG_PUSH
2557+RAPIDJSON_DIAG_OFF(padded)
2558+#endif
2559+
2560 RAPIDJSON_NAMESPACE_BEGIN
2561
2562 //! Input byte stream wrapper with a statically bound encoding.
2563@@ -66,7 +65,7 @@
2564 //! Output byte stream wrapper with statically bound encoding.
2565 /*!
2566 \tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE.
2567- \tparam InputByteStream Type of input byte stream. For example, FileWriteStream.
2568+ \tparam OutputByteStream Type of input byte stream. For example, FileWriteStream.
2569 */
2570 template <typename Encoding, typename OutputByteStream>
2571 class EncodedOutputStream {
2572@@ -83,8 +82,8 @@
2573 void Flush() { os_.Flush(); }
2574
2575 // Not implemented
2576- Ch Peek() const { RAPIDJSON_ASSERT(false); }
2577- Ch Take() { RAPIDJSON_ASSERT(false); }
2578+ Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;}
2579+ Ch Take() { RAPIDJSON_ASSERT(false); return 0;}
2580 size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
2581 Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
2582 size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
2583@@ -115,6 +114,7 @@
2584 \param type UTF encoding type if it is not detected from the stream.
2585 */
2586 AutoUTFInputStream(InputByteStream& is, UTFType type = kUTF8) : is_(&is), type_(type), hasBOM_(false) {
2587+ RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE);
2588 DetectType();
2589 static const TakeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Take) };
2590 takeFunc_ = f[type_];
2591@@ -147,11 +147,11 @@
2592 // FF FE UTF-16LE
2593 // EF BB BF UTF-8
2594
2595- const unsigned char* c = (const unsigned char *)is_->Peek4();
2596+ const unsigned char* c = reinterpret_cast<const unsigned char *>(is_->Peek4());
2597 if (!c)
2598 return;
2599
2600- unsigned bom = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
2601+ unsigned bom = static_cast<unsigned>(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24));
2602 hasBOM_ = false;
2603 if (bom == 0xFFFE0000) { type_ = kUTF32BE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
2604 else if (bom == 0x0000FEFF) { type_ = kUTF32LE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
2605@@ -183,21 +183,8 @@
2606 }
2607
2608 // Runtime check whether the size of character type is sufficient. It only perform checks with assertion.
2609- switch (type_) {
2610- case kUTF8:
2611- // Do nothing
2612- break;
2613- case kUTF16LE:
2614- case kUTF16BE:
2615- RAPIDJSON_ASSERT(sizeof(Ch) >= 2);
2616- break;
2617- case kUTF32LE:
2618- case kUTF32BE:
2619- RAPIDJSON_ASSERT(sizeof(Ch) >= 4);
2620- break;
2621- default:
2622- RAPIDJSON_ASSERT(false); // Invalid type
2623- }
2624+ if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2);
2625+ if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4);
2626 }
2627
2628 typedef Ch (*TakeFunc)(InputByteStream& is);
2629@@ -211,7 +198,7 @@
2630 //! Output stream wrapper with dynamically bound encoding and automatic encoding detection.
2631 /*!
2632 \tparam CharType Type of character for writing.
2633- \tparam InputByteStream type of output byte stream to be wrapped.
2634+ \tparam OutputByteStream type of output byte stream to be wrapped.
2635 */
2636 template <typename CharType, typename OutputByteStream>
2637 class AutoUTFOutputStream {
2638@@ -226,22 +213,11 @@
2639 \param putBOM Whether to write BOM at the beginning of the stream.
2640 */
2641 AutoUTFOutputStream(OutputByteStream& os, UTFType type, bool putBOM) : os_(&os), type_(type) {
2642- // RUntime check whether the size of character type is sufficient. It only perform checks with assertion.
2643- switch (type_) {
2644- case kUTF16LE:
2645- case kUTF16BE:
2646- RAPIDJSON_ASSERT(sizeof(Ch) >= 2);
2647- break;
2648- case kUTF32LE:
2649- case kUTF32BE:
2650- RAPIDJSON_ASSERT(sizeof(Ch) >= 4);
2651- break;
2652- case kUTF8:
2653- // Do nothing
2654- break;
2655- default:
2656- RAPIDJSON_ASSERT(false); // Invalid UTFType
2657- }
2658+ RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE);
2659+
2660+ // Runtime check whether the size of character type is sufficient. It only perform checks with assertion.
2661+ if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2);
2662+ if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4);
2663
2664 static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) };
2665 putFunc_ = f[type_];
2666@@ -256,8 +232,8 @@
2667 void Flush() { os_->Flush(); }
2668
2669 // Not implemented
2670- Ch Peek() const { RAPIDJSON_ASSERT(false); }
2671- Ch Take() { RAPIDJSON_ASSERT(false); }
2672+ Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;}
2673+ Ch Take() { RAPIDJSON_ASSERT(false); return 0;}
2674 size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
2675 Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
2676 size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
2677@@ -283,6 +259,10 @@
2678
2679 RAPIDJSON_NAMESPACE_END
2680
2681+#ifdef __clang__
2682+RAPIDJSON_DIAG_POP
2683+#endif
2684+
2685 #ifdef __GNUC__
2686 RAPIDJSON_DIAG_POP
2687 #endif
2688
2689=== modified file 'shorts/xml2json/rapidjson/encodings.h'
2690--- shorts/xml2json/rapidjson/encodings.h 2015-12-02 17:03:41 +0000
2691+++ shorts/xml2json/rapidjson/encodings.h 2016-03-18 09:56:42 +0000
2692@@ -1,22 +1,16 @@
2693-// Copyright (C) 2011 Milo Yip
2694-//
2695-// Permission is hereby granted, free of charge, to any person obtaining a copy
2696-// of this software and associated documentation files (the "Software"), to deal
2697-// in the Software without restriction, including without limitation the rights
2698-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2699-// copies of the Software, and to permit persons to whom the Software is
2700-// furnished to do so, subject to the following conditions:
2701-//
2702-// The above copyright notice and this permission notice shall be included in
2703-// all copies or substantial portions of the Software.
2704-//
2705-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2706-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2707-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2708-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2709-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2710-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2711-// THE SOFTWARE.
2712+// Tencent is pleased to support the open source community by making RapidJSON available.
2713+//
2714+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
2715+//
2716+// Licensed under the MIT License (the "License"); you may not use this file except
2717+// in compliance with the License. You may obtain a copy of the License at
2718+//
2719+// http://opensource.org/licenses/MIT
2720+//
2721+// Unless required by applicable law or agreed to in writing, software distributed
2722+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
2723+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
2724+// specific language governing permissions and limitations under the License.
2725
2726 #ifndef RAPIDJSON_ENCODINGS_H_
2727 #define RAPIDJSON_ENCODINGS_H_
2728@@ -30,6 +24,7 @@
2729 #elif defined(__GNUC__)
2730 RAPIDJSON_DIAG_PUSH
2731 RAPIDJSON_DIAG_OFF(effc++)
2732+RAPIDJSON_DIAG_OFF(overflow)
2733 #endif
2734
2735 RAPIDJSON_NAMESPACE_BEGIN
2736@@ -127,17 +122,17 @@
2737
2738 template <typename InputStream>
2739 static bool Decode(InputStream& is, unsigned* codepoint) {
2740-#define COPY() c = is.Take(); *codepoint = (*codepoint << 6) | ((unsigned char)c & 0x3Fu)
2741-#define TRANS(mask) result &= ((GetRange((unsigned char)c) & mask) != 0)
2742+#define COPY() c = is.Take(); *codepoint = (*codepoint << 6) | (static_cast<unsigned char>(c) & 0x3Fu)
2743+#define TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
2744 #define TAIL() COPY(); TRANS(0x70)
2745- Ch c = is.Take();
2746+ typename InputStream::Ch c = is.Take();
2747 if (!(c & 0x80)) {
2748- *codepoint = (unsigned char)c;
2749+ *codepoint = static_cast<unsigned char>(c);
2750 return true;
2751 }
2752
2753- unsigned char type = GetRange((unsigned char)c);
2754- *codepoint = (0xFF >> type) & (unsigned char)c;
2755+ unsigned char type = GetRange(static_cast<unsigned char>(c));
2756+ *codepoint = (0xFF >> type) & static_cast<unsigned char>(c);
2757 bool result = true;
2758 switch (type) {
2759 case 2: TAIL(); return result;
2760@@ -157,7 +152,7 @@
2761 template <typename InputStream, typename OutputStream>
2762 static bool Validate(InputStream& is, OutputStream& os) {
2763 #define COPY() os.Put(c = is.Take())
2764-#define TRANS(mask) result &= ((GetRange((unsigned char)c) & mask) != 0)
2765+#define TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
2766 #define TAIL() COPY(); TRANS(0x70)
2767 Ch c;
2768 COPY();
2769@@ -165,7 +160,7 @@
2770 return true;
2771
2772 bool result = true;
2773- switch (GetRange((unsigned char)c)) {
2774+ switch (GetRange(static_cast<unsigned char>(c))) {
2775 case 2: TAIL(); return result;
2776 case 3: TAIL(); TAIL(); return result;
2777 case 4: COPY(); TRANS(0x50); TAIL(); return result;
2778@@ -201,12 +196,12 @@
2779 template <typename InputByteStream>
2780 static CharType TakeBOM(InputByteStream& is) {
2781 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2782- Ch c = Take(is);
2783- if ((unsigned char)c != 0xEFu) return c;
2784- c = is.Take();
2785- if ((unsigned char)c != 0xBBu) return c;
2786- c = is.Take();
2787- if ((unsigned char)c != 0xBFu) return c;
2788+ typename InputByteStream::Ch c = Take(is);
2789+ if (static_cast<unsigned char>(c) != 0xEFu) return c;
2790+ c = is.Take();
2791+ if (static_cast<unsigned char>(c) != 0xBBu) return c;
2792+ c = is.Take();
2793+ if (static_cast<unsigned char>(c) != 0xBFu) return c;
2794 c = is.Take();
2795 return c;
2796 }
2797@@ -214,13 +209,15 @@
2798 template <typename InputByteStream>
2799 static Ch Take(InputByteStream& is) {
2800 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2801- return is.Take();
2802+ return static_cast<Ch>(is.Take());
2803 }
2804
2805 template <typename OutputByteStream>
2806 static void PutBOM(OutputByteStream& os) {
2807 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
2808- os.Put(0xEFu); os.Put(0xBBu); os.Put(0xBFu);
2809+ os.Put(static_cast<typename OutputByteStream::Ch>(0xEFu));
2810+ os.Put(static_cast<typename OutputByteStream::Ch>(0xBBu));
2811+ os.Put(static_cast<typename OutputByteStream::Ch>(0xBFu));
2812 }
2813
2814 template <typename OutputByteStream>
2815@@ -267,15 +264,15 @@
2816 template <typename InputStream>
2817 static bool Decode(InputStream& is, unsigned* codepoint) {
2818 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
2819- Ch c = is.Take();
2820+ typename InputStream::Ch c = is.Take();
2821 if (c < 0xD800 || c > 0xDFFF) {
2822- *codepoint = c;
2823+ *codepoint = static_cast<unsigned>(c);
2824 return true;
2825 }
2826 else if (c <= 0xDBFF) {
2827- *codepoint = (c & 0x3FF) << 10;
2828+ *codepoint = (static_cast<unsigned>(c) & 0x3FF) << 10;
2829 c = is.Take();
2830- *codepoint |= (c & 0x3FF);
2831+ *codepoint |= (static_cast<unsigned>(c) & 0x3FF);
2832 *codepoint += 0x10000;
2833 return c >= 0xDC00 && c <= 0xDFFF;
2834 }
2835@@ -286,8 +283,8 @@
2836 static bool Validate(InputStream& is, OutputStream& os) {
2837 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
2838 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
2839- Ch c;
2840- os.Put(c = is.Take());
2841+ typename InputStream::Ch c;
2842+ os.Put(static_cast<typename OutputStream::Ch>(c = is.Take()));
2843 if (c < 0xD800 || c > 0xDFFF)
2844 return true;
2845 else if (c <= 0xDBFF) {
2846@@ -305,28 +302,29 @@
2847 static CharType TakeBOM(InputByteStream& is) {
2848 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2849 CharType c = Take(is);
2850- return (unsigned short)c == 0xFEFFu ? Take(is) : c;
2851+ return static_cast<uint16_t>(c) == 0xFEFFu ? Take(is) : c;
2852 }
2853
2854 template <typename InputByteStream>
2855 static CharType Take(InputByteStream& is) {
2856 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2857- CharType c = (unsigned char)is.Take();
2858- c |= (unsigned char)is.Take() << 8;
2859- return c;
2860+ unsigned c = static_cast<uint8_t>(is.Take());
2861+ c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 8;
2862+ return static_cast<CharType>(c);
2863 }
2864
2865 template <typename OutputByteStream>
2866 static void PutBOM(OutputByteStream& os) {
2867 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
2868- os.Put(0xFFu); os.Put(0xFEu);
2869+ os.Put(static_cast<typename OutputByteStream::Ch>(0xFFu));
2870+ os.Put(static_cast<typename OutputByteStream::Ch>(0xFEu));
2871 }
2872
2873 template <typename OutputByteStream>
2874 static void Put(OutputByteStream& os, CharType c) {
2875 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
2876- os.Put(c & 0xFFu);
2877- os.Put((c >> 8) & 0xFFu);
2878+ os.Put(static_cast<typename OutputByteStream::Ch>(static_cast<unsigned>(c) & 0xFFu));
2879+ os.Put(static_cast<typename OutputByteStream::Ch>((static_cast<unsigned>(c) >> 8) & 0xFFu));
2880 }
2881 };
2882
2883@@ -337,28 +335,29 @@
2884 static CharType TakeBOM(InputByteStream& is) {
2885 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2886 CharType c = Take(is);
2887- return (unsigned short)c == 0xFEFFu ? Take(is) : c;
2888+ return static_cast<uint16_t>(c) == 0xFEFFu ? Take(is) : c;
2889 }
2890
2891 template <typename InputByteStream>
2892 static CharType Take(InputByteStream& is) {
2893 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2894- CharType c = (unsigned char)is.Take() << 8;
2895- c |= (unsigned char)is.Take();
2896- return c;
2897+ unsigned c = static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 8;
2898+ c |= static_cast<uint8_t>(is.Take());
2899+ return static_cast<CharType>(c);
2900 }
2901
2902 template <typename OutputByteStream>
2903 static void PutBOM(OutputByteStream& os) {
2904 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
2905- os.Put(0xFEu); os.Put(0xFFu);
2906+ os.Put(static_cast<typename OutputByteStream::Ch>(0xFEu));
2907+ os.Put(static_cast<typename OutputByteStream::Ch>(0xFFu));
2908 }
2909
2910 template <typename OutputByteStream>
2911 static void Put(OutputByteStream& os, CharType c) {
2912 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
2913- os.Put((c >> 8) & 0xFFu);
2914- os.Put(c & 0xFFu);
2915+ os.Put(static_cast<typename OutputByteStream::Ch>((static_cast<unsigned>(c) >> 8) & 0xFFu));
2916+ os.Put(static_cast<typename OutputByteStream::Ch>(static_cast<unsigned>(c) & 0xFFu));
2917 }
2918 };
2919
2920@@ -411,32 +410,35 @@
2921 static CharType TakeBOM(InputByteStream& is) {
2922 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2923 CharType c = Take(is);
2924- return (unsigned)c == 0x0000FEFFu ? Take(is) : c;
2925+ return static_cast<uint32_t>(c) == 0x0000FEFFu ? Take(is) : c;
2926 }
2927
2928 template <typename InputByteStream>
2929 static CharType Take(InputByteStream& is) {
2930 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2931- CharType c = (unsigned char)is.Take();
2932- c |= (unsigned char)is.Take() << 8;
2933- c |= (unsigned char)is.Take() << 16;
2934- c |= (unsigned char)is.Take() << 24;
2935- return c;
2936+ unsigned c = static_cast<uint8_t>(is.Take());
2937+ c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 8;
2938+ c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 16;
2939+ c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 24;
2940+ return static_cast<CharType>(c);
2941 }
2942
2943 template <typename OutputByteStream>
2944 static void PutBOM(OutputByteStream& os) {
2945 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
2946- os.Put(0xFFu); os.Put(0xFEu); os.Put(0x00u); os.Put(0x00u);
2947+ os.Put(static_cast<typename OutputByteStream::Ch>(0xFFu));
2948+ os.Put(static_cast<typename OutputByteStream::Ch>(0xFEu));
2949+ os.Put(static_cast<typename OutputByteStream::Ch>(0x00u));
2950+ os.Put(static_cast<typename OutputByteStream::Ch>(0x00u));
2951 }
2952
2953 template <typename OutputByteStream>
2954 static void Put(OutputByteStream& os, CharType c) {
2955 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
2956- os.Put(c & 0xFFu);
2957- os.Put((c >> 8) & 0xFFu);
2958- os.Put((c >> 16) & 0xFFu);
2959- os.Put((c >> 24) & 0xFFu);
2960+ os.Put(static_cast<typename OutputByteStream::Ch>(c & 0xFFu));
2961+ os.Put(static_cast<typename OutputByteStream::Ch>((c >> 8) & 0xFFu));
2962+ os.Put(static_cast<typename OutputByteStream::Ch>((c >> 16) & 0xFFu));
2963+ os.Put(static_cast<typename OutputByteStream::Ch>((c >> 24) & 0xFFu));
2964 }
2965 };
2966
2967@@ -447,32 +449,35 @@
2968 static CharType TakeBOM(InputByteStream& is) {
2969 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2970 CharType c = Take(is);
2971- return (unsigned)c == 0x0000FEFFu ? Take(is) : c;
2972+ return static_cast<uint32_t>(c) == 0x0000FEFFu ? Take(is) : c;
2973 }
2974
2975 template <typename InputByteStream>
2976 static CharType Take(InputByteStream& is) {
2977 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
2978- CharType c = (unsigned char)is.Take() << 24;
2979- c |= (unsigned char)is.Take() << 16;
2980- c |= (unsigned char)is.Take() << 8;
2981- c |= (unsigned char)is.Take();
2982- return c;
2983+ unsigned c = static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 24;
2984+ c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 16;
2985+ c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 8;
2986+ c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take()));
2987+ return static_cast<CharType>(c);
2988 }
2989
2990 template <typename OutputByteStream>
2991 static void PutBOM(OutputByteStream& os) {
2992 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
2993- os.Put(0x00u); os.Put(0x00u); os.Put(0xFEu); os.Put(0xFFu);
2994+ os.Put(static_cast<typename OutputByteStream::Ch>(0x00u));
2995+ os.Put(static_cast<typename OutputByteStream::Ch>(0x00u));
2996+ os.Put(static_cast<typename OutputByteStream::Ch>(0xFEu));
2997+ os.Put(static_cast<typename OutputByteStream::Ch>(0xFFu));
2998 }
2999
3000 template <typename OutputByteStream>
3001 static void Put(OutputByteStream& os, CharType c) {
3002 RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
3003- os.Put((c >> 24) & 0xFFu);
3004- os.Put((c >> 16) & 0xFFu);
3005- os.Put((c >> 8) & 0xFFu);
3006- os.Put(c & 0xFFu);
3007+ os.Put(static_cast<typename OutputByteStream::Ch>((c >> 24) & 0xFFu));
3008+ os.Put(static_cast<typename OutputByteStream::Ch>((c >> 16) & 0xFFu));
3009+ os.Put(static_cast<typename OutputByteStream::Ch>((c >> 8) & 0xFFu));
3010+ os.Put(static_cast<typename OutputByteStream::Ch>(c & 0xFFu));
3011 }
3012 };
3013
3014@@ -498,29 +503,29 @@
3015
3016 template <typename InputStream>
3017 static bool Decode(InputStream& is, unsigned* codepoint) {
3018- unsigned char c = static_cast<unsigned char>(is.Take());
3019+ uint8_t c = static_cast<uint8_t>(is.Take());
3020 *codepoint = c;
3021 return c <= 0X7F;
3022 }
3023
3024 template <typename InputStream, typename OutputStream>
3025 static bool Validate(InputStream& is, OutputStream& os) {
3026- unsigned char c = is.Take();
3027- os.Put(c);
3028+ uint8_t c = static_cast<uint8_t>(is.Take());
3029+ os.Put(static_cast<typename OutputStream::Ch>(c));
3030 return c <= 0x7F;
3031 }
3032
3033 template <typename InputByteStream>
3034 static CharType TakeBOM(InputByteStream& is) {
3035 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
3036- Ch c = Take(is);
3037- return c;
3038+ uint8_t c = static_cast<uint8_t>(Take(is));
3039+ return static_cast<Ch>(c);
3040 }
3041
3042 template <typename InputByteStream>
3043 static Ch Take(InputByteStream& is) {
3044 RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
3045- return is.Take();
3046+ return static_cast<Ch>(is.Take());
3047 }
3048
3049 template <typename OutputByteStream>
3050@@ -623,7 +628,7 @@
3051
3052 RAPIDJSON_NAMESPACE_END
3053
3054-#if defined(__GNUC__) || defined(_MSV_VER)
3055+#if defined(__GNUC__) || defined(_MSC_VER)
3056 RAPIDJSON_DIAG_POP
3057 #endif
3058
3059
3060=== modified file 'shorts/xml2json/rapidjson/error/en.h'
3061--- shorts/xml2json/rapidjson/error/en.h 2015-12-02 17:03:41 +0000
3062+++ shorts/xml2json/rapidjson/error/en.h 2016-03-18 09:56:42 +0000
3063@@ -1,28 +1,28 @@
3064-// Copyright (C) 2011 Milo Yip
3065-//
3066-// Permission is hereby granted, free of charge, to any person obtaining a copy
3067-// of this software and associated documentation files (the "Software"), to deal
3068-// in the Software without restriction, including without limitation the rights
3069-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3070-// copies of the Software, and to permit persons to whom the Software is
3071-// furnished to do so, subject to the following conditions:
3072-//
3073-// The above copyright notice and this permission notice shall be included in
3074-// all copies or substantial portions of the Software.
3075-//
3076-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3077-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3078-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3079-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3080-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3081-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3082-// THE SOFTWARE.
3083+// Tencent is pleased to support the open source community by making RapidJSON available.
3084+//
3085+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3086+//
3087+// Licensed under the MIT License (the "License"); you may not use this file except
3088+// in compliance with the License. You may obtain a copy of the License at
3089+//
3090+// http://opensource.org/licenses/MIT
3091+//
3092+// Unless required by applicable law or agreed to in writing, software distributed
3093+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3094+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3095+// specific language governing permissions and limitations under the License.
3096
3097-#ifndef RAPIDJSON_ERROR_EN_H__
3098-#define RAPIDJSON_ERROR_EN_H__
3099+#ifndef RAPIDJSON_ERROR_EN_H_
3100+#define RAPIDJSON_ERROR_EN_H_
3101
3102 #include "error.h"
3103
3104+#ifdef __clang__
3105+RAPIDJSON_DIAG_PUSH
3106+RAPIDJSON_DIAG_OFF(switch-enum)
3107+RAPIDJSON_DIAG_OFF(covered-switch-default)
3108+#endif
3109+
3110 RAPIDJSON_NAMESPACE_BEGIN
3111
3112 //! Maps error code of parsing into error message.
3113@@ -61,11 +61,14 @@
3114 case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
3115 case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
3116
3117- default:
3118- return RAPIDJSON_ERROR_STRING("Unknown error.");
3119+ default: return RAPIDJSON_ERROR_STRING("Unknown error.");
3120 }
3121 }
3122
3123 RAPIDJSON_NAMESPACE_END
3124
3125-#endif // RAPIDJSON_ERROR_EN_H__
3126+#ifdef __clang__
3127+RAPIDJSON_DIAG_POP
3128+#endif
3129+
3130+#endif // RAPIDJSON_ERROR_EN_H_
3131
3132=== modified file 'shorts/xml2json/rapidjson/error/error.h'
3133--- shorts/xml2json/rapidjson/error/error.h 2015-12-02 17:03:41 +0000
3134+++ shorts/xml2json/rapidjson/error/error.h 2016-03-18 09:56:42 +0000
3135@@ -1,25 +1,26 @@
3136-// Copyright (C) 2011 Milo Yip
3137-//
3138-// Permission is hereby granted, free of charge, to any person obtaining a copy
3139-// of this software and associated documentation files (the "Software"), to deal
3140-// in the Software without restriction, including without limitation the rights
3141-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3142-// copies of the Software, and to permit persons to whom the Software is
3143-// furnished to do so, subject to the following conditions:
3144-//
3145-// The above copyright notice and this permission notice shall be included in
3146-// all copies or substantial portions of the Software.
3147-//
3148-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3149-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3150-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3151-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3152-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3153-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3154-// THE SOFTWARE.
3155-
3156-#ifndef RAPIDJSON_ERROR_ERROR_H__
3157-#define RAPIDJSON_ERROR_ERROR_H__
3158+// Tencent is pleased to support the open source community by making RapidJSON available.
3159+//
3160+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3161+//
3162+// Licensed under the MIT License (the "License"); you may not use this file except
3163+// in compliance with the License. You may obtain a copy of the License at
3164+//
3165+// http://opensource.org/licenses/MIT
3166+//
3167+// Unless required by applicable law or agreed to in writing, software distributed
3168+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3169+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3170+// specific language governing permissions and limitations under the License.
3171+
3172+#ifndef RAPIDJSON_ERROR_ERROR_H_
3173+#define RAPIDJSON_ERROR_ERROR_H_
3174+
3175+#include "../rapidjson.h"
3176+
3177+#ifdef __clang__
3178+RAPIDJSON_DIAG_PUSH
3179+RAPIDJSON_DIAG_OFF(padded)
3180+#endif
3181
3182 /*! \file error.h */
3183
3184@@ -103,7 +104,7 @@
3185 \see GenericReader::Parse, GenericDocument::Parse
3186 */
3187 struct ParseResult {
3188-
3189+public:
3190 //! Default constructor, no error.
3191 ParseResult() : code_(kParseErrorNone), offset_(0) {}
3192 //! Constructor to set an error.
3193@@ -147,4 +148,8 @@
3194
3195 RAPIDJSON_NAMESPACE_END
3196
3197-#endif // RAPIDJSON_ERROR_ERROR_H__
3198+#ifdef __clang__
3199+RAPIDJSON_DIAG_POP
3200+#endif
3201+
3202+#endif // RAPIDJSON_ERROR_ERROR_H_
3203
3204=== modified file 'shorts/xml2json/rapidjson/filereadstream.h'
3205--- shorts/xml2json/rapidjson/filereadstream.h 2015-12-02 17:03:41 +0000
3206+++ shorts/xml2json/rapidjson/filereadstream.h 2016-03-18 09:56:42 +0000
3207@@ -1,22 +1,16 @@
3208-// Copyright (C) 2011 Milo Yip
3209-//
3210-// Permission is hereby granted, free of charge, to any person obtaining a copy
3211-// of this software and associated documentation files (the "Software"), to deal
3212-// in the Software without restriction, including without limitation the rights
3213-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3214-// copies of the Software, and to permit persons to whom the Software is
3215-// furnished to do so, subject to the following conditions:
3216-//
3217-// The above copyright notice and this permission notice shall be included in
3218-// all copies or substantial portions of the Software.
3219-//
3220-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3221-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3222-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3223-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3224-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3225-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3226-// THE SOFTWARE.
3227+// Tencent is pleased to support the open source community by making RapidJSON available.
3228+//
3229+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3230+//
3231+// Licensed under the MIT License (the "License"); you may not use this file except
3232+// in compliance with the License. You may obtain a copy of the License at
3233+//
3234+// http://opensource.org/licenses/MIT
3235+//
3236+// Unless required by applicable law or agreed to in writing, software distributed
3237+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3238+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3239+// specific language governing permissions and limitations under the License.
3240
3241 #ifndef RAPIDJSON_FILEREADSTREAM_H_
3242 #define RAPIDJSON_FILEREADSTREAM_H_
3243@@ -24,6 +18,13 @@
3244 #include "rapidjson.h"
3245 #include <cstdio>
3246
3247+#ifdef __clang__
3248+RAPIDJSON_DIAG_PUSH
3249+RAPIDJSON_DIAG_OFF(padded)
3250+RAPIDJSON_DIAG_OFF(unreachable-code)
3251+RAPIDJSON_DIAG_OFF(missing-noreturn)
3252+#endif
3253+
3254 RAPIDJSON_NAMESPACE_BEGIN
3255
3256 //! File byte stream for input using fread().
3257@@ -91,4 +92,8 @@
3258
3259 RAPIDJSON_NAMESPACE_END
3260
3261+#ifdef __clang__
3262+RAPIDJSON_DIAG_POP
3263+#endif
3264+
3265 #endif // RAPIDJSON_FILESTREAM_H_
3266
3267=== modified file 'shorts/xml2json/rapidjson/filewritestream.h'
3268--- shorts/xml2json/rapidjson/filewritestream.h 2015-12-02 17:03:41 +0000
3269+++ shorts/xml2json/rapidjson/filewritestream.h 2016-03-18 09:56:42 +0000
3270@@ -1,22 +1,16 @@
3271-// Copyright (C) 2011 Milo Yip
3272-//
3273-// Permission is hereby granted, free of charge, to any person obtaining a copy
3274-// of this software and associated documentation files (the "Software"), to deal
3275-// in the Software without restriction, including without limitation the rights
3276-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3277-// copies of the Software, and to permit persons to whom the Software is
3278-// furnished to do so, subject to the following conditions:
3279-//
3280-// The above copyright notice and this permission notice shall be included in
3281-// all copies or substantial portions of the Software.
3282-//
3283-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3284-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3285-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3286-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3287-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3288-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3289-// THE SOFTWARE.
3290+// Tencent is pleased to support the open source community by making RapidJSON available.
3291+//
3292+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3293+//
3294+// Licensed under the MIT License (the "License"); you may not use this file except
3295+// in compliance with the License. You may obtain a copy of the License at
3296+//
3297+// http://opensource.org/licenses/MIT
3298+//
3299+// Unless required by applicable law or agreed to in writing, software distributed
3300+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3301+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3302+// specific language governing permissions and limitations under the License.
3303
3304 #ifndef RAPIDJSON_FILEWRITESTREAM_H_
3305 #define RAPIDJSON_FILEWRITESTREAM_H_
3306@@ -24,6 +18,11 @@
3307 #include "rapidjson.h"
3308 #include <cstdio>
3309
3310+#ifdef __clang__
3311+RAPIDJSON_DIAG_PUSH
3312+RAPIDJSON_DIAG_OFF(unreachable-code)
3313+#endif
3314+
3315 RAPIDJSON_NAMESPACE_BEGIN
3316
3317 //! Wrapper of C file stream for input using fread().
3318@@ -63,7 +62,11 @@
3319
3320 void Flush() {
3321 if (current_ != buffer_) {
3322- fwrite(buffer_, 1, static_cast<size_t>(current_ - buffer_), fp_);
3323+ size_t result = fwrite(buffer_, 1, static_cast<size_t>(current_ - buffer_), fp_);
3324+ if (result < static_cast<size_t>(current_ - buffer_)) {
3325+ // failure deliberately ignored at this time
3326+ // added to avoid warn_unused_result build errors
3327+ }
3328 current_ = buffer_;
3329 }
3330 }
3331@@ -94,4 +97,8 @@
3332
3333 RAPIDJSON_NAMESPACE_END
3334
3335+#ifdef __clang__
3336+RAPIDJSON_DIAG_POP
3337+#endif
3338+
3339 #endif // RAPIDJSON_FILESTREAM_H_
3340
3341=== modified file 'shorts/xml2json/rapidjson/internal/biginteger.h'
3342--- shorts/xml2json/rapidjson/internal/biginteger.h 2015-12-02 17:03:41 +0000
3343+++ shorts/xml2json/rapidjson/internal/biginteger.h 2016-03-18 09:56:42 +0000
3344@@ -1,22 +1,16 @@
3345-// Copyright (C) 2011 Milo Yip
3346-//
3347-// Permission is hereby granted, free of charge, to any person obtaining a copy
3348-// of this software and associated documentation files (the "Software"), to deal
3349-// in the Software without restriction, including without limitation the rights
3350-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3351-// copies of the Software, and to permit persons to whom the Software is
3352-// furnished to do so, subject to the following conditions:
3353-//
3354-// The above copyright notice and this permission notice shall be included in
3355-// all copies or substantial portions of the Software.
3356-//
3357-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3358-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3359-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3360-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3361-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3362-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3363-// THE SOFTWARE.
3364+// Tencent is pleased to support the open source community by making RapidJSON available.
3365+//
3366+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3367+//
3368+// Licensed under the MIT License (the "License"); you may not use this file except
3369+// in compliance with the License. You may obtain a copy of the License at
3370+//
3371+// http://opensource.org/licenses/MIT
3372+//
3373+// Unless required by applicable law or agreed to in writing, software distributed
3374+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3375+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3376+// specific language governing permissions and limitations under the License.
3377
3378 #ifndef RAPIDJSON_BIGINTEGER_H_
3379 #define RAPIDJSON_BIGINTEGER_H_
3380@@ -25,6 +19,7 @@
3381
3382 #if defined(_MSC_VER) && defined(_M_AMD64)
3383 #include <intrin.h> // for _umul128
3384+#pragma intrinsic(_umul128)
3385 #endif
3386
3387 RAPIDJSON_NAMESPACE_BEGIN
3388@@ -56,7 +51,16 @@
3389 if (length > 0)
3390 AppendDecimal64(decimals + i, decimals + i + length);
3391 }
3392-
3393+
3394+ BigInteger& operator=(const BigInteger &rhs)
3395+ {
3396+ if (this != &rhs) {
3397+ count_ = rhs.count_;
3398+ std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type));
3399+ }
3400+ return *this;
3401+ }
3402+
3403 BigInteger& operator=(uint64_t u) {
3404 digits_[0] = u;
3405 count_ = 1;
3406@@ -103,7 +107,7 @@
3407 if (u == 1) return *this;
3408 if (*this == 1) return *this = u;
3409
3410- uint32_t k = 0;
3411+ uint64_t k = 0;
3412 for (size_t i = 0; i < count_; i++) {
3413 const uint64_t c = digits_[i] >> 32;
3414 const uint64_t d = digits_[i] & 0xFFFFFFFF;
3415@@ -178,13 +182,10 @@
3416 }
3417
3418 // Compute absolute difference of this and rhs.
3419- // Return false if this < rhs
3420+ // Assume this != rhs
3421 bool Difference(const BigInteger& rhs, BigInteger* out) const {
3422 int cmp = Compare(rhs);
3423- if (cmp == 0) {
3424- *out = BigInteger(0);
3425- return false;
3426- }
3427+ RAPIDJSON_ASSERT(cmp != 0);
3428 const BigInteger *a, *b; // Makes a > b
3429 bool ret;
3430 if (cmp < 0) { a = &rhs; b = this; ret = true; }
3431@@ -239,7 +240,7 @@
3432 uint64_t r = 0;
3433 for (const char* p = begin; p != end; ++p) {
3434 RAPIDJSON_ASSERT(*p >= '0' && *p <= '9');
3435- r = r * 10 + (*p - '0');
3436+ r = r * 10u + static_cast<unsigned>(*p - '0');
3437 }
3438 return r;
3439 }
3440@@ -252,9 +253,10 @@
3441 (*outHigh)++;
3442 return low;
3443 #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
3444- unsigned __int128 p = static_cast<unsigned __int128>(a) * static_cast<unsigned __int128>(b);
3445+ __extension__ typedef unsigned __int128 uint128;
3446+ uint128 p = static_cast<uint128>(a) * static_cast<uint128>(b);
3447 p += k;
3448- *outHigh = p >> 64;
3449+ *outHigh = static_cast<uint64_t>(p >> 64);
3450 return static_cast<uint64_t>(p);
3451 #else
3452 const uint64_t a0 = a & 0xFFFFFFFF, a1 = a >> 32, b0 = b & 0xFFFFFFFF, b1 = b >> 32;
3453@@ -274,12 +276,6 @@
3454 #endif
3455 }
3456
3457- static Type FullAdd(Type a, Type b, bool inCarry, bool* outCarry) {
3458- Type c = a + b + (inCarry ? 1 : 0);
3459- *outCarry = c < a;
3460- return c;
3461- }
3462-
3463 static const size_t kBitCount = 3328; // 64bit * 54 > 10^1000
3464 static const size_t kCapacity = kBitCount / sizeof(Type);
3465 static const size_t kTypeBit = sizeof(Type) * 8;
3466
3467=== modified file 'shorts/xml2json/rapidjson/internal/diyfp.h'
3468--- shorts/xml2json/rapidjson/internal/diyfp.h 2015-12-02 17:03:41 +0000
3469+++ shorts/xml2json/rapidjson/internal/diyfp.h 2016-03-18 09:56:42 +0000
3470@@ -1,22 +1,16 @@
3471-// Copyright (C) 2011 Milo Yip
3472-//
3473-// Permission is hereby granted, free of charge, to any person obtaining a copy
3474-// of this software and associated documentation files (the "Software"), to deal
3475-// in the Software without restriction, including without limitation the rights
3476-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3477-// copies of the Software, and to permit persons to whom the Software is
3478-// furnished to do so, subject to the following conditions:
3479-//
3480-// The above copyright notice and this permission notice shall be included in
3481-// all copies or substantial portions of the Software.
3482-//
3483-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3484-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3485-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3486-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3487-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3488-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3489-// THE SOFTWARE.
3490+// Tencent is pleased to support the open source community by making RapidJSON available.
3491+//
3492+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3493+//
3494+// Licensed under the MIT License (the "License"); you may not use this file except
3495+// in compliance with the License. You may obtain a copy of the License at
3496+//
3497+// http://opensource.org/licenses/MIT
3498+//
3499+// Unless required by applicable law or agreed to in writing, software distributed
3500+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3501+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3502+// specific language governing permissions and limitations under the License.
3503
3504 // This is a C++ header-only implementation of Grisu2 algorithm from the publication:
3505 // Loitsch, Florian. "Printing floating-point numbers quickly and accurately with
3506@@ -25,11 +19,12 @@
3507 #ifndef RAPIDJSON_DIYFP_H_
3508 #define RAPIDJSON_DIYFP_H_
3509
3510-#if defined(_MSC_VER)
3511+#include "../rapidjson.h"
3512+
3513+#if defined(_MSC_VER) && defined(_M_AMD64)
3514 #include <intrin.h>
3515-#if defined(_M_AMD64)
3516 #pragma intrinsic(_BitScanReverse64)
3517-#endif
3518+#pragma intrinsic(_umul128)
3519 #endif
3520
3521 RAPIDJSON_NAMESPACE_BEGIN
3522@@ -40,6 +35,11 @@
3523 RAPIDJSON_DIAG_OFF(effc++)
3524 #endif
3525
3526+#ifdef __clang__
3527+RAPIDJSON_DIAG_PUSH
3528+RAPIDJSON_DIAG_OFF(padded)
3529+#endif
3530+
3531 struct DiyFp {
3532 DiyFp() {}
3533
3534@@ -51,7 +51,7 @@
3535 uint64_t u64;
3536 } u = { d };
3537
3538- int biased_e = (u.u64 & kDpExponentMask) >> kDpSignificandSize;
3539+ int biased_e = static_cast<int>((u.u64 & kDpExponentMask) >> kDpSignificandSize);
3540 uint64_t significand = (u.u64 & kDpSignificandMask);
3541 if (biased_e != 0) {
3542 f = significand + kDpHiddenBit;
3543@@ -75,8 +75,9 @@
3544 h++;
3545 return DiyFp(h, e + rhs.e + 64);
3546 #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
3547- unsigned __int128 p = static_cast<unsigned __int128>(f) * static_cast<unsigned __int128>(rhs.f);
3548- uint64_t h = p >> 64;
3549+ __extension__ typedef unsigned __int128 uint128;
3550+ uint128 p = static_cast<uint128>(f) * static_cast<uint128>(rhs.f);
3551+ uint64_t h = static_cast<uint64_t>(p >> 64);
3552 uint64_t l = static_cast<uint64_t>(p);
3553 if (l & (uint64_t(1) << 63)) // rounding
3554 h++;
3555@@ -140,25 +141,9 @@
3556 double d;
3557 uint64_t u64;
3558 }u;
3559- uint64_t significand = f;
3560- int exponent = e;
3561- while (significand > kDpHiddenBit + kDpSignificandMask) {
3562- significand >>= 1;
3563- exponent++;
3564- }
3565- while (exponent > kDpDenormalExponent && (significand & kDpHiddenBit) == 0) {
3566- significand <<= 1;
3567- exponent--;
3568- }
3569- if (exponent >= kDpMaxExponent) {
3570- u.u64 = kDpExponentMask; // Infinity
3571- return u.d;
3572- }
3573- else if (exponent < kDpDenormalExponent)
3574- return 0.0;
3575- const uint64_t be = (exponent == kDpDenormalExponent && (significand & kDpHiddenBit) == 0) ? 0 :
3576- static_cast<uint64_t>(exponent + kDpExponentBias);
3577- u.u64 = (significand & kDpSignificandMask) | (be << kDpSignificandSize);
3578+ const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 :
3579+ static_cast<uint64_t>(e + kDpExponentBias);
3580+ u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize);
3581 return u.d;
3582 }
3583
3584@@ -243,7 +228,7 @@
3585 //int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
3586 double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive
3587 int k = static_cast<int>(dk);
3588- if (k != dk)
3589+ if (dk - k > 0.0)
3590 k++;
3591
3592 unsigned index = static_cast<unsigned>((k >> 3) + 1);
3593@@ -253,8 +238,8 @@
3594 }
3595
3596 inline DiyFp GetCachedPower10(int exp, int *outExp) {
3597- unsigned index = (exp + 348) / 8;
3598- *outExp = -348 + index * 8;
3599+ unsigned index = (static_cast<unsigned>(exp) + 348u) / 8u;
3600+ *outExp = -348 + static_cast<int>(index) * 8;
3601 return GetCachedPowerByIndex(index);
3602 }
3603
3604@@ -262,6 +247,11 @@
3605 RAPIDJSON_DIAG_POP
3606 #endif
3607
3608+#ifdef __clang__
3609+RAPIDJSON_DIAG_POP
3610+RAPIDJSON_DIAG_OFF(padded)
3611+#endif
3612+
3613 } // namespace internal
3614 RAPIDJSON_NAMESPACE_END
3615
3616
3617=== modified file 'shorts/xml2json/rapidjson/internal/dtoa.h'
3618--- shorts/xml2json/rapidjson/internal/dtoa.h 2015-12-02 17:03:41 +0000
3619+++ shorts/xml2json/rapidjson/internal/dtoa.h 2016-03-18 09:56:42 +0000
3620@@ -1,22 +1,16 @@
3621-// Copyright (C) 2011 Milo Yip
3622-//
3623-// Permission is hereby granted, free of charge, to any person obtaining a copy
3624-// of this software and associated documentation files (the "Software"), to deal
3625-// in the Software without restriction, including without limitation the rights
3626-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3627-// copies of the Software, and to permit persons to whom the Software is
3628-// furnished to do so, subject to the following conditions:
3629-//
3630-// The above copyright notice and this permission notice shall be included in
3631-// all copies or substantial portions of the Software.
3632-//
3633-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3634-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3635-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3636-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3637-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3638-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3639-// THE SOFTWARE.
3640+// Tencent is pleased to support the open source community by making RapidJSON available.
3641+//
3642+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3643+//
3644+// Licensed under the MIT License (the "License"); you may not use this file except
3645+// in compliance with the License. You may obtain a copy of the License at
3646+//
3647+// http://opensource.org/licenses/MIT
3648+//
3649+// Unless required by applicable law or agreed to in writing, software distributed
3650+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3651+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3652+// specific language governing permissions and limitations under the License.
3653
3654 // This is a C++ header-only implementation of Grisu2 algorithm from the publication:
3655 // Loitsch, Florian. "Printing floating-point numbers quickly and accurately with
3656@@ -27,6 +21,7 @@
3657
3658 #include "itoa.h" // GetDigitsLut()
3659 #include "diyfp.h"
3660+#include "ieee754.h"
3661
3662 RAPIDJSON_NAMESPACE_BEGIN
3663 namespace internal {
3664@@ -55,8 +50,10 @@
3665 if (n < 1000000) return 6;
3666 if (n < 10000000) return 7;
3667 if (n < 100000000) return 8;
3668- if (n < 1000000000) return 9;
3669- return 10;
3670+ // Will not reach 10 digits in DigitGen()
3671+ //if (n < 1000000000) return 9;
3672+ //return 10;
3673+ return 9;
3674 }
3675
3676 inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) {
3677@@ -65,13 +62,12 @@
3678 const DiyFp wp_w = Mp - W;
3679 uint32_t p1 = static_cast<uint32_t>(Mp.f >> -one.e);
3680 uint64_t p2 = Mp.f & (one.f - 1);
3681- int kappa = CountDecimalDigit32(p1);
3682+ unsigned kappa = CountDecimalDigit32(p1); // kappa in [0, 9]
3683 *len = 0;
3684
3685 while (kappa > 0) {
3686- uint32_t d;
3687+ uint32_t d = 0;
3688 switch (kappa) {
3689- case 10: d = p1 / 1000000000; p1 %= 1000000000; break;
3690 case 9: d = p1 / 100000000; p1 %= 100000000; break;
3691 case 8: d = p1 / 10000000; p1 %= 10000000; break;
3692 case 7: d = p1 / 1000000; p1 %= 1000000; break;
3693@@ -81,14 +77,7 @@
3694 case 3: d = p1 / 100; p1 %= 100; break;
3695 case 2: d = p1 / 10; p1 %= 10; break;
3696 case 1: d = p1; p1 = 0; break;
3697- default:
3698-#if defined(_MSC_VER)
3699- __assume(0);
3700-#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
3701- __builtin_unreachable();
3702-#else
3703- d = 0;
3704-#endif
3705+ default:;
3706 }
3707 if (d || *len)
3708 buffer[(*len)++] = static_cast<char>('0' + static_cast<char>(d));
3709@@ -112,7 +101,7 @@
3710 kappa--;
3711 if (p2 < delta) {
3712 *K += kappa;
3713- GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-kappa]);
3714+ GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-static_cast<int>(kappa)]);
3715 return;
3716 }
3717 }
3718@@ -169,14 +158,14 @@
3719 }
3720 else if (0 < kk && kk <= 21) {
3721 // 1234e-2 -> 12.34
3722- std::memmove(&buffer[kk + 1], &buffer[kk], length - kk);
3723+ std::memmove(&buffer[kk + 1], &buffer[kk], static_cast<size_t>(length - kk));
3724 buffer[kk] = '.';
3725 return &buffer[length + 1];
3726 }
3727 else if (-6 < kk && kk <= 0) {
3728 // 1234e-6 -> 0.001234
3729 const int offset = 2 - kk;
3730- std::memmove(&buffer[offset], &buffer[0], length);
3731+ std::memmove(&buffer[offset], &buffer[0], static_cast<size_t>(length));
3732 buffer[0] = '0';
3733 buffer[1] = '.';
3734 for (int i = 2; i < offset; i++)
3735@@ -190,7 +179,7 @@
3736 }
3737 else {
3738 // 1234e30 -> 1.234e33
3739- std::memmove(&buffer[2], &buffer[1], length - 1);
3740+ std::memmove(&buffer[2], &buffer[1], static_cast<size_t>(length - 1));
3741 buffer[1] = '.';
3742 buffer[length + 1] = 'e';
3743 return WriteExponent(kk - 1, &buffer[0 + length + 2]);
3744@@ -198,7 +187,10 @@
3745 }
3746
3747 inline char* dtoa(double value, char* buffer) {
3748- if (value == 0) {
3749+ Double d(value);
3750+ if (d.IsZero()) {
3751+ if (d.Sign())
3752+ *buffer++ = '-'; // -0.0, Issue #289
3753 buffer[0] = '0';
3754 buffer[1] = '.';
3755 buffer[2] = '0';
3756
3757=== modified file 'shorts/xml2json/rapidjson/internal/ieee754.h'
3758--- shorts/xml2json/rapidjson/internal/ieee754.h 2015-12-02 17:03:41 +0000
3759+++ shorts/xml2json/rapidjson/internal/ieee754.h 2016-03-18 09:56:42 +0000
3760@@ -1,22 +1,16 @@
3761-// Copyright (C) 2011 Milo Yip
3762-//
3763-// Permission is hereby granted, free of charge, to any person obtaining a copy
3764-// of this software and associated documentation files (the "Software"), to deal
3765-// in the Software without restriction, including without limitation the rights
3766-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3767-// copies of the Software, and to permit persons to whom the Software is
3768-// furnished to do so, subject to the following conditions:
3769-//
3770-// The above copyright notice and this permission notice shall be included in
3771-// all copies or substantial portions of the Software.
3772-//
3773-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3774-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3775-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3776-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3777-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3778-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3779-// THE SOFTWARE.
3780+// Tencent is pleased to support the open source community by making RapidJSON available.
3781+//
3782+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3783+//
3784+// Licensed under the MIT License (the "License"); you may not use this file except
3785+// in compliance with the License. You may obtain a copy of the License at
3786+//
3787+// http://opensource.org/licenses/MIT
3788+//
3789+// Unless required by applicable law or agreed to in writing, software distributed
3790+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3791+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3792+// specific language governing permissions and limitations under the License.
3793
3794 #ifndef RAPIDJSON_IEEE754_
3795 #define RAPIDJSON_IEEE754_
3796@@ -29,36 +23,29 @@
3797 class Double {
3798 public:
3799 Double() {}
3800- Double(double d) : d(d) {}
3801- Double(uint64_t u) : u(u) {}
3802+ Double(double d) : d_(d) {}
3803+ Double(uint64_t u) : u_(u) {}
3804
3805- double Value() const { return d; }
3806- uint64_t Uint64Value() const { return u; }
3807+ double Value() const { return d_; }
3808+ uint64_t Uint64Value() const { return u_; }
3809
3810 double NextPositiveDouble() const {
3811 RAPIDJSON_ASSERT(!Sign());
3812- return Double(u + 1).Value();
3813- }
3814-
3815- double PreviousPositiveDouble() const {
3816- RAPIDJSON_ASSERT(!Sign());
3817- if (d == 0.0)
3818- return 0.0;
3819- else
3820- return Double(u - 1).Value();
3821- }
3822-
3823- bool Sign() const { return (u & kSignMask) != 0; }
3824- uint64_t Significand() const { return u & kSignificandMask; }
3825- int Exponent() const { return ((u & kExponentMask) >> kSignificandSize) - kExponentBias; }
3826-
3827- bool IsNan() const { return (u & kExponentMask) == kExponentMask && Significand() != 0; }
3828- bool IsInf() const { return (u & kExponentMask) == kExponentMask && Significand() == 0; }
3829- bool IsNormal() const { return (u & kExponentMask) != 0 || Significand() == 0; }
3830+ return Double(u_ + 1).Value();
3831+ }
3832+
3833+ bool Sign() const { return (u_ & kSignMask) != 0; }
3834+ uint64_t Significand() const { return u_ & kSignificandMask; }
3835+ int Exponent() const { return static_cast<int>(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); }
3836+
3837+ bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; }
3838+ bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; }
3839+ bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; }
3840+ bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; }
3841
3842 uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); }
3843 int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; }
3844- uint64_t ToBias() const { return (u & kSignMask) ? ~u + 1 : u | kSignMask; }
3845+ uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; }
3846
3847 static unsigned EffectiveSignificandSize(int order) {
3848 if (order >= -1021)
3849@@ -66,7 +53,7 @@
3850 else if (order <= -1074)
3851 return 0;
3852 else
3853- return order + 1074;
3854+ return static_cast<unsigned>(order) + 1074;
3855 }
3856
3857 private:
3858@@ -79,8 +66,8 @@
3859 static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000);
3860
3861 union {
3862- double d;
3863- uint64_t u;
3864+ double d_;
3865+ uint64_t u_;
3866 };
3867 };
3868
3869
3870=== modified file 'shorts/xml2json/rapidjson/internal/itoa.h'
3871--- shorts/xml2json/rapidjson/internal/itoa.h 2015-12-02 17:03:41 +0000
3872+++ shorts/xml2json/rapidjson/internal/itoa.h 2016-03-18 09:56:42 +0000
3873@@ -1,26 +1,22 @@
3874-// Copyright (C) 2011 Milo Yip
3875-//
3876-// Permission is hereby granted, free of charge, to any person obtaining a copy
3877-// of this software and associated documentation files (the "Software"), to deal
3878-// in the Software without restriction, including without limitation the rights
3879-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3880-// copies of the Software, and to permit persons to whom the Software is
3881-// furnished to do so, subject to the following conditions:
3882-//
3883-// The above copyright notice and this permission notice shall be included in
3884-// all copies or substantial portions of the Software.
3885-//
3886-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3887-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3888-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3889-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3890-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3891-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3892-// THE SOFTWARE.
3893+// Tencent is pleased to support the open source community by making RapidJSON available.
3894+//
3895+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3896+//
3897+// Licensed under the MIT License (the "License"); you may not use this file except
3898+// in compliance with the License. You may obtain a copy of the License at
3899+//
3900+// http://opensource.org/licenses/MIT
3901+//
3902+// Unless required by applicable law or agreed to in writing, software distributed
3903+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3904+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3905+// specific language governing permissions and limitations under the License.
3906
3907 #ifndef RAPIDJSON_ITOA_
3908 #define RAPIDJSON_ITOA_
3909
3910+#include "../rapidjson.h"
3911+
3912 RAPIDJSON_NAMESPACE_BEGIN
3913 namespace internal {
3914
3915@@ -115,12 +111,13 @@
3916 }
3917
3918 inline char* i32toa(int32_t value, char* buffer) {
3919+ uint32_t u = static_cast<uint32_t>(value);
3920 if (value < 0) {
3921 *buffer++ = '-';
3922- value = -value;
3923+ u = ~u + 1;
3924 }
3925
3926- return u32toa(static_cast<uint32_t>(value), buffer);
3927+ return u32toa(u, buffer);
3928 }
3929
3930 inline char* u64toa(uint64_t value, char* buffer) {
3931@@ -292,12 +289,13 @@
3932 }
3933
3934 inline char* i64toa(int64_t value, char* buffer) {
3935+ uint64_t u = static_cast<uint64_t>(value);
3936 if (value < 0) {
3937 *buffer++ = '-';
3938- value = -value;
3939+ u = ~u + 1;
3940 }
3941
3942- return u64toa(static_cast<uint64_t>(value), buffer);
3943+ return u64toa(u, buffer);
3944 }
3945
3946 } // namespace internal
3947
3948=== modified file 'shorts/xml2json/rapidjson/internal/meta.h'
3949--- shorts/xml2json/rapidjson/internal/meta.h 2015-12-02 17:03:41 +0000
3950+++ shorts/xml2json/rapidjson/internal/meta.h 2016-03-18 09:56:42 +0000
3951@@ -1,29 +1,21 @@
3952-// Copyright (C) 2011 Milo Yip
3953-//
3954-// Permission is hereby granted, free of charge, to any person obtaining a copy
3955-// of this software and associated documentation files (the "Software"), to deal
3956-// in the Software without restriction, including without limitation the rights
3957-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3958-// copies of the Software, and to permit persons to whom the Software is
3959-// furnished to do so, subject to the following conditions:
3960-//
3961-// The above copyright notice and this permission notice shall be included in
3962-// all copies or substantial portions of the Software.
3963-//
3964-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3965-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3966-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3967-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3968-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3969-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3970-// THE SOFTWARE.
3971+// Tencent is pleased to support the open source community by making RapidJSON available.
3972+//
3973+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3974+//
3975+// Licensed under the MIT License (the "License"); you may not use this file except
3976+// in compliance with the License. You may obtain a copy of the License at
3977+//
3978+// http://opensource.org/licenses/MIT
3979+//
3980+// Unless required by applicable law or agreed to in writing, software distributed
3981+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3982+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
3983+// specific language governing permissions and limitations under the License.
3984
3985 #ifndef RAPIDJSON_INTERNAL_META_H_
3986 #define RAPIDJSON_INTERNAL_META_H_
3987
3988-#ifndef RAPIDJSON_RAPIDJSON_H_
3989-#error <rapidjson.h> not yet included. Do not include this file directly.
3990-#endif
3991+#include "../rapidjson.h"
3992
3993 #ifdef __GNUC__
3994 RAPIDJSON_DIAG_PUSH
3995
3996=== modified file 'shorts/xml2json/rapidjson/internal/pow10.h'
3997--- shorts/xml2json/rapidjson/internal/pow10.h 2015-12-02 17:03:41 +0000
3998+++ shorts/xml2json/rapidjson/internal/pow10.h 2016-03-18 09:56:42 +0000
3999@@ -1,26 +1,22 @@
4000-// Copyright (C) 2011 Milo Yip
4001-//
4002-// Permission is hereby granted, free of charge, to any person obtaining a copy
4003-// of this software and associated documentation files (the "Software"), to deal
4004-// in the Software without restriction, including without limitation the rights
4005-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4006-// copies of the Software, and to permit persons to whom the Software is
4007-// furnished to do so, subject to the following conditions:
4008-//
4009-// The above copyright notice and this permission notice shall be included in
4010-// all copies or substantial portions of the Software.
4011-//
4012-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4013-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4014-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4015-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4016-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4017-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4018-// THE SOFTWARE.
4019+// Tencent is pleased to support the open source community by making RapidJSON available.
4020+//
4021+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4022+//
4023+// Licensed under the MIT License (the "License"); you may not use this file except
4024+// in compliance with the License. You may obtain a copy of the License at
4025+//
4026+// http://opensource.org/licenses/MIT
4027+//
4028+// Unless required by applicable law or agreed to in writing, software distributed
4029+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4030+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
4031+// specific language governing permissions and limitations under the License.
4032
4033 #ifndef RAPIDJSON_POW10_
4034 #define RAPIDJSON_POW10_
4035
4036+#include "../rapidjson.h"
4037+
4038 RAPIDJSON_NAMESPACE_BEGIN
4039 namespace internal {
4040
4041
4042=== modified file 'shorts/xml2json/rapidjson/internal/stack.h'
4043--- shorts/xml2json/rapidjson/internal/stack.h 2015-12-02 17:03:41 +0000
4044+++ shorts/xml2json/rapidjson/internal/stack.h 2016-03-18 09:56:42 +0000
4045@@ -1,26 +1,23 @@
4046-// Copyright (C) 2011 Milo Yip
4047-//
4048-// Permission is hereby granted, free of charge, to any person obtaining a copy
4049-// of this software and associated documentation files (the "Software"), to deal
4050-// in the Software without restriction, including without limitation the rights
4051-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4052-// copies of the Software, and to permit persons to whom the Software is
4053-// furnished to do so, subject to the following conditions:
4054-//
4055-// The above copyright notice and this permission notice shall be included in
4056-// all copies or substantial portions of the Software.
4057-//
4058-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4059-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4060-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4061-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4062-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4063-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4064-// THE SOFTWARE.
4065+// Tencent is pleased to support the open source community by making RapidJSON available.
4066+//
4067+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4068+//
4069+// Licensed under the MIT License (the "License"); you may not use this file except
4070+// in compliance with the License. You may obtain a copy of the License at
4071+//
4072+// http://opensource.org/licenses/MIT
4073+//
4074+// Unless required by applicable law or agreed to in writing, software distributed
4075+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4076+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
4077+// specific language governing permissions and limitations under the License.
4078
4079 #ifndef RAPIDJSON_INTERNAL_STACK_H_
4080 #define RAPIDJSON_INTERNAL_STACK_H_
4081
4082+#include "../rapidjson.h"
4083+#include "swap.h"
4084+
4085 RAPIDJSON_NAMESPACE_BEGIN
4086 namespace internal {
4087
4088@@ -85,6 +82,15 @@
4089 }
4090 #endif
4091
4092+ void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT {
4093+ internal::Swap(allocator_, rhs.allocator_);
4094+ internal::Swap(ownAllocator_, rhs.ownAllocator_);
4095+ internal::Swap(stack_, rhs.stack_);
4096+ internal::Swap(stackTop_, rhs.stackTop_);
4097+ internal::Swap(stackEnd_, rhs.stackEnd_);
4098+ internal::Swap(initialCapacity_, rhs.initialCapacity_);
4099+ }
4100+
4101 void Clear() { stackTop_ = stack_; }
4102
4103 void ShrinkToFit() {
4104@@ -126,9 +132,16 @@
4105 }
4106
4107 template<typename T>
4108- T* Bottom() { return (T*)stack_; }
4109-
4110- Allocator& GetAllocator() { return *allocator_; }
4111+ T* Bottom() { return reinterpret_cast<T*>(stack_); }
4112+
4113+ bool HasAllocator() const {
4114+ return allocator_ != 0;
4115+ }
4116+
4117+ Allocator& GetAllocator() {
4118+ RAPIDJSON_ASSERT(allocator_);
4119+ return *allocator_;
4120+ }
4121 bool Empty() const { return stackTop_ == stack_; }
4122 size_t GetSize() const { return static_cast<size_t>(stackTop_ - stack_); }
4123 size_t GetCapacity() const { return static_cast<size_t>(stackEnd_ - stack_); }
4124@@ -155,7 +168,7 @@
4125
4126 void Resize(size_t newCapacity) {
4127 const size_t size = GetSize(); // Backup the current size
4128- stack_ = (char*)allocator_->Realloc(stack_, GetCapacity(), newCapacity);
4129+ stack_ = static_cast<char*>(allocator_->Realloc(stack_, GetCapacity(), newCapacity));
4130 stackTop_ = stack_ + size;
4131 stackEnd_ = stack_ + newCapacity;
4132 }
4133
4134=== modified file 'shorts/xml2json/rapidjson/internal/strfunc.h'
4135--- shorts/xml2json/rapidjson/internal/strfunc.h 2015-12-02 17:03:41 +0000
4136+++ shorts/xml2json/rapidjson/internal/strfunc.h 2016-03-18 09:56:42 +0000
4137@@ -1,26 +1,22 @@
4138-// Copyright (C) 2011 Milo Yip
4139-//
4140-// Permission is hereby granted, free of charge, to any person obtaining a copy
4141-// of this software and associated documentation files (the "Software"), to deal
4142-// in the Software without restriction, including without limitation the rights
4143-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4144-// copies of the Software, and to permit persons to whom the Software is
4145-// furnished to do so, subject to the following conditions:
4146-//
4147-// The above copyright notice and this permission notice shall be included in
4148-// all copies or substantial portions of the Software.
4149-//
4150-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4151-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4152-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4153-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4154-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4155-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4156-// THE SOFTWARE.
4157+// Tencent is pleased to support the open source community by making RapidJSON available.
4158+//
4159+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4160+//
4161+// Licensed under the MIT License (the "License"); you may not use this file except
4162+// in compliance with the License. You may obtain a copy of the License at
4163+//
4164+// http://opensource.org/licenses/MIT
4165+//
4166+// Unless required by applicable law or agreed to in writing, software distributed
4167+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4168+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
4169+// specific language governing permissions and limitations under the License.
4170
4171 #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_
4172 #define RAPIDJSON_INTERNAL_STRFUNC_H_
4173
4174+#include "../rapidjson.h"
4175+
4176 RAPIDJSON_NAMESPACE_BEGIN
4177 namespace internal {
4178
4179
4180=== modified file 'shorts/xml2json/rapidjson/internal/strtod.h'
4181--- shorts/xml2json/rapidjson/internal/strtod.h 2015-12-02 17:03:41 +0000
4182+++ shorts/xml2json/rapidjson/internal/strtod.h 2016-03-18 09:56:42 +0000
4183@@ -1,22 +1,16 @@
4184-// Copyright (C) 2011 Milo Yip
4185-//
4186-// Permission is hereby granted, free of charge, to any person obtaining a copy
4187-// of this software and associated documentation files (the "Software"), to deal
4188-// in the Software without restriction, including without limitation the rights
4189-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4190-// copies of the Software, and to permit persons to whom the Software is
4191-// furnished to do so, subject to the following conditions:
4192-//
4193-// The above copyright notice and this permission notice shall be included in
4194-// all copies or substantial portions of the Software.
4195-//
4196-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4197-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4198-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4199-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4200-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4201-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4202-// THE SOFTWARE.
4203+// Tencent is pleased to support the open source community by making RapidJSON available.
4204+//
4205+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4206+//
4207+// Licensed under the MIT License (the "License"); you may not use this file except
4208+// in compliance with the License. You may obtain a copy of the License at
4209+//
4210+// http://opensource.org/licenses/MIT
4211+//
4212+// Unless required by applicable law or agreed to in writing, software distributed
4213+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4214+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
4215+// specific language governing permissions and limitations under the License.
4216
4217 #ifndef RAPIDJSON_STRTOD_
4218 #define RAPIDJSON_STRTOD_
4219@@ -58,7 +52,7 @@
4220 return m;
4221 }
4222
4223-inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp, bool* adjustToNegative) {
4224+inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) {
4225 const Double db(b);
4226 const uint64_t bInt = db.IntegerSignificand();
4227 const int bExp = db.IntegerExponent();
4228@@ -101,28 +95,18 @@
4229 hS_Exp2 -= common_Exp2;
4230
4231 BigInteger dS = d;
4232- dS.MultiplyPow5(dS_Exp5) <<= dS_Exp2;
4233+ dS.MultiplyPow5(static_cast<unsigned>(dS_Exp5)) <<= static_cast<unsigned>(dS_Exp2);
4234
4235 BigInteger bS(bInt);
4236- bS.MultiplyPow5(bS_Exp5) <<= bS_Exp2;
4237+ bS.MultiplyPow5(static_cast<unsigned>(bS_Exp5)) <<= static_cast<unsigned>(bS_Exp2);
4238
4239 BigInteger hS(1);
4240- hS.MultiplyPow5(hS_Exp5) <<= hS_Exp2;
4241+ hS.MultiplyPow5(static_cast<unsigned>(hS_Exp5)) <<= static_cast<unsigned>(hS_Exp2);
4242
4243 BigInteger delta(0);
4244- *adjustToNegative = dS.Difference(bS, &delta);
4245+ dS.Difference(bS, &delta);
4246
4247- int cmp = delta.Compare(hS);
4248- // If delta is within 1/2 ULP, check for special case when significand is power of two.
4249- // In this case, need to compare with 1/2h in the lower bound.
4250- if (cmp < 0 && *adjustToNegative && // within and dS < bS
4251- db.IsNormal() && (bInt & (bInt - 1)) == 0 && // Power of 2
4252- db.Uint64Value() != RAPIDJSON_UINT64_C2(0x00100000, 0x00000000)) // minimum normal number must not do this
4253- {
4254- delta <<= 1;
4255- return delta.Compare(hS);
4256- }
4257- return cmp;
4258+ return delta.Compare(hS);
4259 }
4260
4261 inline bool StrtodFast(double d, int p, double* result) {
4262@@ -150,7 +134,7 @@
4263 if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) ||
4264 (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5'))
4265 break;
4266- significand = significand * 10 + (decimals[i] - '0');
4267+ significand = significand * 10u + static_cast<unsigned>(decimals[i] - '0');
4268 }
4269
4270 if (i < length && decimals[i] >= '5') // Rounding
4271@@ -165,7 +149,7 @@
4272 v = v.Normalize();
4273 error <<= -v.e;
4274
4275- const int dExp = (int)decimalPosition - (int)i + exp;
4276+ const int dExp = static_cast<int>(decimalPosition) - static_cast<int>(i) + exp;
4277
4278 int actualExp;
4279 DiyFp cachedPower = GetCachedPower10(dExp, &actualExp);
4280@@ -179,10 +163,10 @@
4281 DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 00000000), -44), // 10^6
4282 DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 00000000), -40) // 10^7
4283 };
4284- int adjustment = dExp - actualExp - 1;
4285+ int adjustment = dExp - actualExp - 1;
4286 RAPIDJSON_ASSERT(adjustment >= 0 && adjustment < 7);
4287 v = v * kPow10[adjustment];
4288- if (length + adjustment > 19) // has more digits than decimal digits in 64-bit
4289+ if (length + static_cast<unsigned>(adjustment)> 19u) // has more digits than decimal digits in 64-bit
4290 error += kUlp / 2;
4291 }
4292
4293@@ -200,43 +184,42 @@
4294 unsigned scaleExp = (precisionSize + kUlpShift) - 63;
4295 v.f >>= scaleExp;
4296 v.e += scaleExp;
4297- error = (error >> scaleExp) + 1 + kUlp;
4298+ error = (error >> scaleExp) + 1 + static_cast<int>(kUlp);
4299 precisionSize -= scaleExp;
4300 }
4301
4302- DiyFp rounded(v.f >> precisionSize, v.e + precisionSize);
4303+ DiyFp rounded(v.f >> precisionSize, v.e + static_cast<int>(precisionSize));
4304 const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp;
4305 const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp;
4306- if (precisionBits >= halfWay + error)
4307+ if (precisionBits >= halfWay + static_cast<unsigned>(error)) {
4308 rounded.f++;
4309+ if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340)
4310+ rounded.f >>= 1;
4311+ rounded.e++;
4312+ }
4313+ }
4314
4315 *result = rounded.ToDouble();
4316
4317- return halfWay - error >= precisionBits || precisionBits >= halfWay + error;
4318+ return halfWay - static_cast<unsigned>(error) >= precisionBits || precisionBits >= halfWay + static_cast<unsigned>(error);
4319 }
4320
4321 inline double StrtodBigInteger(double approx, const char* decimals, size_t length, size_t decimalPosition, int exp) {
4322 const BigInteger dInt(decimals, length);
4323- const int dExp = (int)decimalPosition - (int)length + exp;
4324+ const int dExp = static_cast<int>(decimalPosition) - static_cast<int>(length) + exp;
4325 Double a(approx);
4326- for (int i = 0; i < 10; i++) {
4327- bool adjustToNegative;
4328- int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp, &adjustToNegative);
4329- if (cmp < 0)
4330- return a.Value(); // within half ULP
4331- else if (cmp == 0) {
4332- // Round towards even
4333- if (a.Significand() & 1)
4334- return adjustToNegative ? a.PreviousPositiveDouble() : a.NextPositiveDouble();
4335- else
4336- return a.Value();
4337- }
4338- else // adjustment
4339- a = adjustToNegative ? a.PreviousPositiveDouble() : a.NextPositiveDouble();
4340+ int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp);
4341+ if (cmp < 0)
4342+ return a.Value(); // within half ULP
4343+ else if (cmp == 0) {
4344+ // Round towards even
4345+ if (a.Significand() & 1)
4346+ return a.NextPositiveDouble();
4347+ else
4348+ return a.Value();
4349 }
4350-
4351- // This should not happen, but in case there is really a bug, break the infinite-loop
4352- return a.Value();
4353+ else // adjustment
4354+ return a.NextPositiveDouble();
4355 }
4356
4357 inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) {
4358@@ -263,8 +246,10 @@
4359
4360 // Trim right-most digits
4361 const int kMaxDecimalDigit = 780;
4362- if ((int)length > kMaxDecimalDigit) {
4363- exp += (int(length) - kMaxDecimalDigit);
4364+ if (static_cast<int>(length) > kMaxDecimalDigit) {
4365+ int delta = (static_cast<int>(length) - kMaxDecimalDigit);
4366+ exp += delta;
4367+ decimalPosition -= static_cast<unsigned>(delta);
4368 length = kMaxDecimalDigit;
4369 }
4370
4371
4372=== added file 'shorts/xml2json/rapidjson/internal/swap.h'
4373--- shorts/xml2json/rapidjson/internal/swap.h 1970-01-01 00:00:00 +0000
4374+++ shorts/xml2json/rapidjson/internal/swap.h 2016-03-18 09:56:42 +0000
4375@@ -0,0 +1,37 @@
4376+// Tencent is pleased to support the open source community by making RapidJSON available.
4377+//
4378+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4379+//
4380+// Licensed under the MIT License (the "License"); you may not use this file except
4381+// in compliance with the License. You may obtain a copy of the License at
4382+//
4383+// http://opensource.org/licenses/MIT
4384+//
4385+// Unless required by applicable law or agreed to in writing, software distributed
4386+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4387+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
4388+// specific language governing permissions and limitations under the License.
4389+
4390+#ifndef RAPIDJSON_INTERNAL_SWAP_H_
4391+#define RAPIDJSON_INTERNAL_SWAP_H_
4392+
4393+#include "../rapidjson.h"
4394+
4395+RAPIDJSON_NAMESPACE_BEGIN
4396+namespace internal {
4397+
4398+//! Custom swap() to avoid dependency on C++ <algorithm> header
4399+/*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only.
4400+ \note This has the same semantics as std::swap().
4401+*/
4402+template <typename T>
4403+inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT {
4404+ T tmp = a;
4405+ a = b;
4406+ b = tmp;
4407+}
4408+
4409+} // namespace internal
4410+RAPIDJSON_NAMESPACE_END
4411+
4412+#endif // RAPIDJSON_INTERNAL_SWAP_H_
4413
4414=== modified file 'shorts/xml2json/rapidjson/memorybuffer.h'
4415--- shorts/xml2json/rapidjson/memorybuffer.h 2015-12-02 17:03:41 +0000
4416+++ shorts/xml2json/rapidjson/memorybuffer.h 2016-03-18 09:56:42 +0000
4417@@ -1,22 +1,16 @@
4418-// Copyright (C) 2011 Milo Yip
4419-//
4420-// Permission is hereby granted, free of charge, to any person obtaining a copy
4421-// of this software and associated documentation files (the "Software"), to deal
4422-// in the Software without restriction, including without limitation the rights
4423-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4424-// copies of the Software, and to permit persons to whom the Software is
4425-// furnished to do so, subject to the following conditions:
4426-//
4427-// The above copyright notice and this permission notice shall be included in
4428-// all copies or substantial portions of the Software.
4429-//
4430-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4431-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4432-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4433-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4434-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4435-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4436-// THE SOFTWARE.
4437+// Tencent is pleased to support the open source community by making RapidJSON available.
4438+//
4439+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4440+//
4441+// Licensed under the MIT License (the "License"); you may not use this file except
4442+// in compliance with the License. You may obtain a copy of the License at
4443+//
4444+// http://opensource.org/licenses/MIT
4445+//
4446+// Unless required by applicable law or agreed to in writing, software distributed
4447+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4448+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
4449+// specific language governing permissions and limitations under the License.
4450
4451 #ifndef RAPIDJSON_MEMORYBUFFER_H_
4452 #define RAPIDJSON_MEMORYBUFFER_H_
4453
4454=== modified file 'shorts/xml2json/rapidjson/memorystream.h'
4455--- shorts/xml2json/rapidjson/memorystream.h 2015-12-02 17:03:41 +0000
4456+++ shorts/xml2json/rapidjson/memorystream.h 2016-03-18 09:56:42 +0000
4457@@ -1,28 +1,28 @@
4458-// Copyright (C) 2011 Milo Yip
4459-//
4460-// Permission is hereby granted, free of charge, to any person obtaining a copy
4461-// of this software and associated documentation files (the "Software"), to deal
4462-// in the Software without restriction, including without limitation the rights
4463-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4464-// copies of the Software, and to permit persons to whom the Software is
4465-// furnished to do so, subject to the following conditions:
4466-//
4467-// The above copyright notice and this permission notice shall be included in
4468-// all copies or substantial portions of the Software.
4469-//
4470-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4471-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4472-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4473-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4474-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4475-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4476-// THE SOFTWARE.
4477+// Tencent is pleased to support the open source community by making RapidJSON available.
4478+//
4479+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4480+//
4481+// Licensed under the MIT License (the "License"); you may not use this file except
4482+// in compliance with the License. You may obtain a copy of the License at
4483+//
4484+// http://opensource.org/licenses/MIT
4485+//
4486+// Unless required by applicable law or agreed to in writing, software distributed
4487+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4488+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
4489+// specific language governing permissions and limitations under the License.
4490
4491 #ifndef RAPIDJSON_MEMORYSTREAM_H_
4492 #define RAPIDJSON_MEMORYSTREAM_H_
4493
4494 #include "rapidjson.h"
4495
4496+#ifdef __clang__
4497+RAPIDJSON_DIAG_PUSH
4498+RAPIDJSON_DIAG_OFF(unreachable-code)
4499+RAPIDJSON_DIAG_OFF(missing-noreturn)
4500+#endif
4501+
4502 RAPIDJSON_NAMESPACE_BEGIN
4503
4504 //! Represents an in-memory input byte stream.
4505@@ -64,4 +64,8 @@
4506
4507 RAPIDJSON_NAMESPACE_END
4508
4509+#ifdef __clang__
4510+RAPIDJSON_DIAG_POP
4511+#endif
4512+
4513 #endif // RAPIDJSON_MEMORYBUFFER_H_
4514
4515=== modified file 'shorts/xml2json/rapidjson/msinttypes/inttypes.h'
4516--- shorts/xml2json/rapidjson/msinttypes/inttypes.h 2015-12-02 17:03:41 +0000
4517+++ shorts/xml2json/rapidjson/msinttypes/inttypes.h 2016-03-18 09:56:42 +0000
4518@@ -30,6 +30,10 @@
4519 //
4520 ///////////////////////////////////////////////////////////////////////////////
4521
4522+// The above software in this distribution may have been modified by
4523+// THL A29 Limited ("Tencent Modifications").
4524+// All Tencent Modifications are Copyright (C) 2015 THL A29 Limited.
4525+
4526 #ifndef _MSC_VER // [
4527 #error "Use this header only with Microsoft Visual C++ compilers!"
4528 #endif // _MSC_VER ]
4529
4530=== modified file 'shorts/xml2json/rapidjson/msinttypes/stdint.h'
4531--- shorts/xml2json/rapidjson/msinttypes/stdint.h 2015-12-02 17:03:41 +0000
4532+++ shorts/xml2json/rapidjson/msinttypes/stdint.h 2016-03-18 09:56:42 +0000
4533@@ -30,6 +30,10 @@
4534 //
4535 ///////////////////////////////////////////////////////////////////////////////
4536
4537+// The above software in this distribution may have been modified by
4538+// THL A29 Limited ("Tencent Modifications").
4539+// All Tencent Modifications are Copyright (C) 2015 THL A29 Limited.
4540+
4541 #ifndef _MSC_VER // [
4542 #error "Use this header only with Microsoft Visual C++ compilers!"
4543 #endif // _MSC_VER ]
4544@@ -85,14 +89,14 @@
4545 #include <limits.h>
4546
4547 // For Visual Studio 6 in C++ mode and for many Visual Studio versions when
4548-// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
4549-// or compiler give many errors like this:
4550+// compiling for ARM we have to wrap <wchar.h> include with 'extern "C++" {}'
4551+// or compiler would give many errors like this:
4552 // error C2733: second C linkage of overloaded function 'wmemchr' not allowed
4553-#ifdef __cplusplus
4554+#if defined(__cplusplus) && !defined(_M_ARM)
4555 extern "C" {
4556 #endif
4557 # include <wchar.h>
4558-#ifdef __cplusplus
4559+#if defined(__cplusplus) && !defined(_M_ARM)
4560 }
4561 #endif
4562
4563
4564=== added file 'shorts/xml2json/rapidjson/pointer.h'
4565--- shorts/xml2json/rapidjson/pointer.h 1970-01-01 00:00:00 +0000
4566+++ shorts/xml2json/rapidjson/pointer.h 2016-03-18 09:56:42 +0000
4567@@ -0,0 +1,1326 @@
4568+// Tencent is pleased to support the open source community by making RapidJSON available.
4569+//
4570+// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4571+//
4572+// Licensed under the MIT License (the "License"); you may not use this file except
4573+// in compliance with the License. You may obtain a copy of the License at
4574+//
4575+// http://opensource.org/licenses/MIT
4576+//
4577+// Unless required by applicable law or agreed to in writing, software distributed
4578+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4579+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
4580+// specific language governing permissions and limitations under the License.
4581+
4582+#ifndef RAPIDJSON_POINTER_H_
4583+#define RAPIDJSON_POINTER_H_
4584+
4585+#include "document.h"
4586+#include "internal/itoa.h"
4587+
4588+#ifdef __clang__
4589+RAPIDJSON_DIAG_PUSH
4590+RAPIDJSON_DIAG_OFF(switch-enum)
4591+#endif
4592+
4593+RAPIDJSON_NAMESPACE_BEGIN
4594+
4595+static const SizeType kPointerInvalidIndex = ~SizeType(0); //!< Represents an invalid index in GenericPointer::Token
4596+
4597+//! Error code of parsing.
4598+/*! \ingroup RAPIDJSON_ERRORS
4599+ \see GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode
4600+*/
4601+enum PointerParseErrorCode {
4602+ kPointerParseErrorNone = 0, //!< The parse is successful
4603+
4604+ kPointerParseErrorTokenMustBeginWithSolidus, //!< A token must begin with a '/'
4605+ kPointerParseErrorInvalidEscape, //!< Invalid escape
4606+ kPointerParseErrorInvalidPercentEncoding, //!< Invalid percent encoding in URI fragment
4607+ kPointerParseErrorCharacterMustPercentEncode //!< A character must percent encoded in URI fragment
4608+};
4609+
4610+///////////////////////////////////////////////////////////////////////////////
4611+// GenericPointer
4612+
4613+//! Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
4614+/*!
4615+ This class implements RFC 6901 "JavaScript Object Notation (JSON) Pointer"
4616+ (https://tools.ietf.org/html/rfc6901).
4617+
4618+ A JSON pointer is for identifying a specific value in a JSON document
4619+ (GenericDocument). It can simplify coding of DOM tree manipulation, because it
4620+ can access multiple-level depth of DOM tree with single API call.
4621+
4622+ After it parses a string representation (e.g. "/foo/0" or URI fragment
4623+ representation (e.g. "#/foo/0") into its internal representation (tokens),
4624+ it can be used to resolve a specific value in multiple documents, or sub-tree
4625+ of documents.
4626+
4627+ Contrary to GenericValue, Pointer can be copy constructed and copy assigned.
4628+ Apart from assignment, a Pointer cannot be modified after construction.
4629+
4630+ Although Pointer is very convenient, please aware that constructing Pointer
4631+ involves parsing and dynamic memory allocation. A special constructor with user-
4632+ supplied tokens eliminates these.
4633+
4634+ GenericPointer depends on GenericDocument and GenericValue.
4635+
4636+ \tparam ValueType The value type of the DOM tree. E.g. GenericValue<UTF8<> >
4637+ \tparam Allocator The allocator type for allocating memory for internal representation.
4638+
4639+ \note GenericPointer uses same encoding of ValueType.
4640+ However, Allocator of GenericPointer is independent of Allocator of Value.
4641+*/
4642+template <typename ValueType, typename Allocator = CrtAllocator>
4643+class GenericPointer {
4644+public:
4645+ typedef typename ValueType::EncodingType EncodingType; //!< Encoding type from Value
4646+ typedef typename ValueType::Ch Ch; //!< Character type from Value
4647+
4648+ //! A token is the basic units of internal representation.
4649+ /*!
4650+ A JSON pointer string representation "/foo/123" is parsed to two tokens:
4651+ "foo" and 123. 123 will be represented in both numeric form and string form.
4652+ They are resolved according to the actual value type (object or array).
4653+
4654+ For token that are not numbers, or the numeric value is out of bound
4655+ (greater than limits of SizeType), they are only treated as string form
4656+ (i.e. the token's index will be equal to kPointerInvalidIndex).
4657+
4658+ This struct is public so that user can create a Pointer without parsing and
4659+ allocation, using a special constructor.
4660+ */
4661+ struct Token {
4662+ const Ch* name; //!< Name of the token. It has null character at the end but it can contain null character.
4663+ SizeType length; //!< Length of the name.
4664+ SizeType index; //!< A valid array index, if it is not equal to kPointerInvalidIndex.
4665+ };
4666+
4667+ //!@name Constructors and destructor.
4668+ //@{
4669+
4670+ //! Default constructor.
4671+ GenericPointer() : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}
4672+
4673+ //! Constructor that parses a string or URI fragment representation.
4674+ /*!
4675+ \param source A null-terminated, string or URI fragment representation of JSON pointer.
4676+ \param allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.
4677+ */
4678+ explicit GenericPointer(const Ch* source, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
4679+ Parse(source, internal::StrLen(source));
4680+ }
4681+
4682+#if RAPIDJSON_HAS_STDSTRING
4683+ //! Constructor that parses a string or URI fragment representation.
4684+ /*!
4685+ \param source A string or URI fragment representation of JSON pointer.
4686+ \param allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.
4687+ \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING.
4688+ */
4689+ explicit GenericPointer(const std::basic_string<Ch>& source, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
4690+ Parse(source.c_str(), source.size());
4691+ }
4692+#endif
4693+
4694+ //! Constructor that parses a string or URI fragment representation, with length of the source string.
4695+ /*!
4696+ \param source A string or URI fragment representation of JSON pointer.
4697+ \param length Length of source.
4698+ \param allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.
4699+ \note Slightly faster than the overload without length.
4700+ */
4701+ GenericPointer(const Ch* source, size_t length, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
4702+ Parse(source, length);
4703+ }
4704+
4705+ //! Constructor with user-supplied tokens.
4706+ /*!
4707+ This constructor let user supplies const array of tokens.
4708+ This prevents the parsing process and eliminates allocation.
4709+ This is preferred for memory constrained environments.
4710+
4711+ \param tokens An constant array of tokens representing the JSON pointer.
4712+ \param tokenCount Number of tokens.
4713+
4714+ \b Example
4715+ \code
4716+ #define NAME(s) { s, sizeof(s) / sizeof(s[0]) - 1, kPointerInvalidIndex }
4717+ #define INDEX(i) { #i, sizeof(#i) - 1, i }
4718+
4719+ static const Pointer::Token kTokens[] = { NAME("foo"), INDEX(123) };
4720+ static const Pointer p(kTokens, sizeof(kTokens) / sizeof(kTokens[0]));
4721+ // Equivalent to static const Pointer p("/foo/123");
4722+
4723+ #undef NAME
4724+ #undef INDEX
4725+ \endcode
4726+ */
4727+ GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast<Token*>(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}
4728+
4729+ //! Copy constructor.
4730+ GenericPointer(const GenericPointer& rhs) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
4731+ *this = rhs;
4732+ }
4733+
4734+ //! Destructor.
4735+ ~GenericPointer() {
4736+ if (nameBuffer_) // If user-supplied tokens constructor is used, nameBuffer_ is nullptr and tokens_ are not deallocated.
4737+ Allocator::Free(tokens_);
4738+ RAPIDJSON_DELETE(ownAllocator_);
4739+ }
4740+
4741+ //! Assignment operator.
4742+ GenericPointer& operator=(const GenericPointer& rhs) {
4743+ if (this != &rhs) {
4744+ // Do not delete ownAllcator
4745+ if (nameBuffer_)
4746+ Allocator::Free(tokens_);
4747+
4748+ tokenCount_ = rhs.tokenCount_;
4749+ parseErrorOffset_ = rhs.parseErrorOffset_;
4750+ parseErrorCode_ = rhs.parseErrorCode_;
4751+
4752+ if (rhs.nameBuffer_)
4753+ CopyFromRaw(rhs); // Normally parsed tokens.
4754+ else {
4755+ tokens_ = rhs.tokens_; // User supplied const tokens.
4756+ nameBuffer_ = 0;
4757+ }
4758+ }
4759+ return *this;
4760+ }
4761+
4762+ //@}
4763+
4764+ //!@name Append token
4765+ //@{
4766+
4767+ //! Append a token and return a new Pointer
4768+ /*!
4769+ \param token Token to be appended.
4770+ \param allocator Allocator for the newly return Pointer.
4771+ \return A new Pointer with appended token.
4772+ */
4773+ GenericPointer Append(const Token& token, Allocator* allocator = 0) const {
4774+ GenericPointer r;
4775+ r.allocator_ = allocator;
4776+ Ch *p = r.CopyFromRaw(*this, 1, token.length + 1);
4777+ std::memcpy(p, token.name, (token.length + 1) * sizeof(Ch));
4778+ r.tokens_[tokenCount_].name = p;
4779+ r.tokens_[tokenCount_].length = token.length;
4780+ r.tokens_[tokenCount_].index = token.index;
4781+ return r;
4782+ }
4783+
4784+ //! Append a name token with length, and return a new Pointer
4785+ /*!
4786+ \param name Name to be appended.
4787+ \param length Length of name.
4788+ \param allocator Allocator for the newly return Pointer.
4789+ \return A new Pointer with appended token.
4790+ */
4791+ GenericPointer Append(const Ch* name, SizeType length, Allocator* allocator = 0) const {
4792+ Token token = { name, length, kPointerInvalidIndex };
4793+ return Append(token, allocator);
4794+ }
4795+
4796+ //! Append a name token without length, and return a new Pointer
4797+ /*!
4798+ \param name Name (const Ch*) to be appended.
4799+ \param allocator Allocator for the newly return Pointer.
4800+ \return A new Pointer with appended token.
4801+ */
4802+ template <typename T>
4803+ RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >), (GenericPointer))
4804+ Append(T* name, Allocator* allocator = 0) const {
4805+ return Append(name, StrLen(name), allocator);
4806+ }
4807+
4808+#if RAPIDJSON_HAS_STDSTRING
4809+ //! Append a name token, and return a new Pointer
4810+ /*!
4811+ \param name Name to be appended.
4812+ \param allocator Allocator for the newly return Pointer.
4813+ \return A new Pointer with appended token.
4814+ */
4815+ GenericPointer Append(const std::basic_string<Ch>& name, Allocator* allocator = 0) const {
4816+ return Append(name.c_str(), static_cast<SizeType>(name.size()), allocator);
4817+ }
4818+#endif
4819+
4820+ //! Append a index token, and return a new Pointer
4821+ /*!
4822+ \param index Index to be appended.
4823+ \param allocator Allocator for the newly return Pointer.
4824+ \return A new Pointer with appended token.
4825+ */
4826+ GenericPointer Append(SizeType index, Allocator* allocator = 0) const {
4827+ char buffer[21];
4828+ char* end = sizeof(SizeType) == 4 ? internal::u32toa(index, buffer) : internal::u64toa(index, buffer);
4829+ SizeType length = static_cast<SizeType>(end - buffer);
4830+ buffer[length] = '\0';
4831+
4832+ if (sizeof(Ch) == 1) {
4833+ Token token = { reinterpret_cast<Ch*>(buffer), length, index };
4834+ return Append(token, allocator);
4835+ }
4836+ else {
4837+ Ch name[21];
4838+ for (size_t i = 0; i <= length; i++)
4839+ name[i] = buffer[i];
4840+ Token token = { name, length, index };
4841+ return Append(token, allocator);
4842+ }
4843+ }
4844+
4845+ //! Append a token by value, and return a new Pointer
4846+ /*!
4847+ \param token token to be appended.
4848+ \param allocator Allocator for the newly return Pointer.
4849+ \return A new Pointer with appended token.
4850+ */
4851+ GenericPointer Append(const ValueType& token, Allocator* allocator = 0) const {
4852+ if (token.IsString())
4853+ return Append(token.GetString(), token.GetStringLength(), allocator);
4854+ else {
4855+ RAPIDJSON_ASSERT(token.IsUint64());
4856+ RAPIDJSON_ASSERT(token.GetUint64() <= SizeType(~0));
4857+ return Append(static_cast<SizeType>(token.GetUint64()), allocator);
4858+ }
4859+ }
4860+
4861+ //!@name Handling Parse Error
4862+ //@{
4863+
4864+ //! Check whether this is a valid pointer.
4865+ bool IsValid() const { return parseErrorCode_ == kPointerParseErrorNone; }
4866+
4867+ //! Get the parsing error offset in code unit.
4868+ size_t GetParseErrorOffset() const { return parseErrorOffset_; }
4869+
4870+ //! Get the parsing error code.
4871+ PointerParseErrorCode GetParseErrorCode() const { return parseErrorCode_; }
4872+
4873+ //@}
4874+
4875+ //!@name Tokens
4876+ //@{
4877+
4878+ //! Get the token array (const version only).
4879+ const Token* GetTokens() const { return tokens_; }
4880+
4881+ //! Get the number of tokens.
4882+ size_t GetTokenCount() const { return tokenCount_; }
4883+
4884+ //@}
4885+
4886+ //!@name Equality/inequality operators
4887+ //@{
4888+
4889+ //! Equality operator.
4890+ /*!
4891+ \note When any pointers are invalid, always returns false.
4892+ */
4893+ bool operator==(const GenericPointer& rhs) const {
4894+ if (!IsValid() || !rhs.IsValid() || tokenCount_ != rhs.tokenCount_)
4895+ return false;
4896+
4897+ for (size_t i = 0; i < tokenCount_; i++) {
4898+ if (tokens_[i].index != rhs.tokens_[i].index ||
4899+ tokens_[i].length != rhs.tokens_[i].length ||
4900+ (tokens_[i].length != 0 && std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch)* tokens_[i].length) != 0))
4901+ {
4902+ return false;
4903+ }
4904+ }
4905+
4906+ return true;
4907+ }
4908+
4909+ //! Inequality operator.
4910+ /*!
4911+ \note When any pointers are invalid, always returns true.
4912+ */
4913+ bool operator!=(const GenericPointer& rhs) const { return !(*this == rhs); }
4914+
4915+ //@}
4916+
4917+ //!@name Stringify
4918+ //@{
4919+
4920+ //! Stringify the pointer into string representation.
4921+ /*!
4922+ \tparam OutputStream Type of output stream.
4923+ \param os The output stream.
4924+ */
4925+ template<typename OutputStream>
4926+ bool Stringify(OutputStream& os) const {
4927+ return Stringify<false, OutputStream>(os);
4928+ }
4929+
4930+ //! Stringify the pointer into URI fragment representation.
4931+ /*!
4932+ \tparam OutputStream Type of output stream.
4933+ \param os The output stream.
4934+ */
4935+ template<typename OutputStream>
4936+ bool StringifyUriFragment(OutputStream& os) const {
4937+ return Stringify<true, OutputStream>(os);
4938+ }
4939+
4940+ //@}
4941+
4942+ //!@name Create value
4943+ //@{
4944+
4945+ //! Create a value in a subtree.
4946+ /*!
4947+ If the value is not exist, it creates all parent values and a JSON Null value.
4948+ So it always succeed and return the newly created or existing value.
4949+
4950+ Remind that it may change types of parents according to tokens, so it
4951+ potentially removes previously stored values. For example, if a document
4952+ was an array, and "/foo" is used to create a value, then the document
4953+ will be changed to an object, and all existing array elements are lost.
4954+
4955+ \param root Root value of a DOM subtree to be resolved. It can be any value other than document root.
4956+ \param allocator Allocator for creating the values if the specified value or its parents are not exist.
4957+ \param alreadyExist If non-null, it stores whether the resolved value is already exist.
4958+ \return The resolved newly created (a JSON Null value), or already exists value.
4959+ */
4960+ ValueType& Create(ValueType& root, typename ValueType::AllocatorType& allocator, bool* alreadyExist = 0) const {
4961+ RAPIDJSON_ASSERT(IsValid());
4962+ ValueType* v = &root;
4963+ bool exist = true;
4964+ for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
4965+ if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
4966+ v->PushBack(ValueType().Move(), allocator);
4967+ v = &((*v)[v->Size() - 1]);
4968+ exist = false;
4969+ }
4970+ else {
4971+ if (t->index == kPointerInvalidIndex) { // must be object name
4972+ if (!v->IsObject())
4973+ v->SetObject(); // Change to Object
4974+ }
4975+ else { // object name or array index
4976+ if (!v->IsArray() && !v->IsObject())
4977+ v->SetArray(); // Change to Array
4978+ }
4979+
4980+ if (v->IsArray()) {
4981+ if (t->index >= v->Size()) {
4982+ v->Reserve(t->index + 1, allocator);
4983+ while (t->index >= v->Size())
4984+ v->PushBack(ValueType().Move(), allocator);
4985+ exist = false;
4986+ }
4987+ v = &((*v)[t->index]);
4988+ }
4989+ else {
4990+ typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
4991+ if (m == v->MemberEnd()) {
4992+ v->AddMember(ValueType(t->name, t->length, allocator).Move(), ValueType().Move(), allocator);
4993+ v = &(--v->MemberEnd())->value; // Assumes AddMember() appends at the end
4994+ exist = false;
4995+ }
4996+ else
4997+ v = &m->value;
4998+ }
4999+ }
5000+ }
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches