Merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba

Proposed by Paul J. Lucas on 2013-06-03
Status: Merged
Approved by: Chris Hillery on 2013-06-11
Approved revision: 11512
Merged at revision: 11504
Proposed branch: lp:~zorba-coders/zorba/bug-1180220
Merge into: lp:zorba
Diff against target: 7823 lines (+2000/-2932)
128 files modified
ChangeLog (+1/-0)
bin/path_util.cpp (+8/-8)
bin/zorbacmd.cpp (+17/-28)
include/zorba/api_shared_types.h (+60/-64)
include/zorba/base64_stream.h (+2/-1)
include/zorba/file.h (+0/-100)
include/zorba/internal/cxx_util.h (+6/-4)
include/zorba/internal/unique_ptr.h (+10/-8)
include/zorba/internal/ztd.h (+3/-1)
include/zorba/stemmer.h (+2/-1)
include/zorba/thesaurus.h (+2/-1)
include/zorba/tokenizer.h (+7/-5)
include/zorba/transcode_stream.h (+2/-1)
include/zorba/user_exception.h (+4/-3)
include/zorba/util/error_util.h (+11/-16)
include/zorba/util/file.h (+0/-122)
include/zorba/util/fs_util.h (+627/-0)
include/zorba/util/path.h (+0/-105)
include/zorba/util/stream_util.h (+48/-0)
modules/ExternalModules.conf (+10/-9)
modules/org/expath/ns/file.xq.src/file.cpp (+340/-441)
modules/org/expath/ns/file.xq.src/file.h (+8/-6)
modules/org/expath/ns/file.xq.src/file_function.cpp (+58/-87)
modules/org/expath/ns/file.xq.src/file_function.h (+4/-10)
src/api/CMakeLists.txt (+0/-5)
src/api/fileimpl.cpp (+0/-404)
src/api/fileimpl.h (+0/-94)
src/api/staticcontextimpl.cpp (+3/-3)
src/api/stemmer_wrappers.cpp (+1/-1)
src/api/thesaurus_wrappers.cpp (+1/-1)
src/api/zorba_string.cpp (+1/-1)
src/compiler/expression/ftnode.cpp (+1/-1)
src/compiler/expression/ftnode.h (+1/-2)
src/compiler/expression/ftnode_visitor.cpp (+1/-1)
src/compiler/parser/ft_types.cpp (+1/-1)
src/context/default_uri_mappers.cpp (+1/-1)
src/context/default_url_resolvers.cpp (+13/-8)
src/context/dynamic_loader.cpp (+6/-5)
src/diagnostics/assert.h (+1/-1)
src/diagnostics/diagnostic_en.xml (+0/-4)
src/diagnostics/pregenerated/dict_en.cpp (+0/-1)
src/diagnostics/pregenerated/dict_zed_keys.h (+0/-1)
src/diagnostics/user_exception.h (+1/-1)
src/diagnostics/xquery_diagnostics.h (+1/-2)
src/diagnostics/xquery_exception.cpp (+1/-1)
src/precompiled/stdafx.h (+1/-1)
src/runtime/full_text/apply.cpp (+2/-2)
src/runtime/full_text/ft_module_util.h (+3/-3)
src/runtime/full_text/ft_query_item.cpp (+2/-1)
src/runtime/full_text/ft_stop_words_set.cpp (+1/-1)
src/runtime/full_text/ft_token_matcher.cpp (+3/-3)
src/runtime/full_text/ft_token_seq_iterator.cpp (+2/-1)
src/runtime/full_text/ft_util.h (+1/-1)
src/runtime/full_text/ftcontains_visitor.cpp (+2/-1)
src/runtime/full_text/icu_tokenizer.cpp (+1/-1)
src/runtime/full_text/icu_tokenizer.h (+1/-2)
src/runtime/full_text/stemmer.cpp (+2/-1)
src/runtime/full_text/stemmer/sb_stemmer.cpp (+2/-1)
src/runtime/full_text/thesauri/encoded_list.h (+1/-1)
src/runtime/full_text/thesauri/wn_thesaurus.cpp (+8/-11)
src/runtime/full_text/thesaurus.cpp (+16/-12)
src/runtime/json/json_impl.cpp (+1/-2)
src/runtime/json/jsonml_array.cpp (+1/-1)
src/runtime/json/snelson.cpp (+1/-1)
src/runtime/util/doc_uri_heuristics.cpp (+23/-17)
src/store/naive/ft_token_store.h (+2/-1)
src/store/naive/naive_ft_token_iterator.cpp (+2/-1)
src/store/naive/store.cpp (+2/-1)
src/unit_tests/CMakeLists.txt (+2/-6)
src/unit_tests/test_ato_.cpp (+2/-1)
src/unit_tests/test_fs_iterator.cpp (+0/-54)
src/unit_tests/test_fs_util.cpp (+178/-0)
src/unit_tests/test_mem_sizeof.cpp (+2/-1)
src/unit_tests/test_string.cpp (+3/-3)
src/unit_tests/unit_test_list.h (+1/-4)
src/unit_tests/unit_tests.cpp (+1/-5)
src/util/CMakeLists.txt (+0/-1)
src/util/base64_util.h (+1/-1)
src/util/cxx_util.cpp (+2/-2)
src/util/error_util.cpp (+16/-11)
src/util/file.cpp (+0/-337)
src/util/fs_util.cpp (+232/-120)
src/util/fs_util.h (+2/-429)
src/util/fx/fxcharheap.cpp (+0/-2)
src/util/hash/hashtable.h (+2/-2)
src/util/hexbinary_util.h (+2/-1)
src/util/http_util.cpp (+6/-4)
src/util/icu_regex.cpp (+2/-1)
src/util/icu_regex.h (+2/-1)
src/util/icu_streambuf.cpp (+1/-1)
src/util/json_parser.h (+1/-1)
src/util/mem_streambuf.cpp (+2/-1)
src/util/mmap_file.cpp (+3/-2)
src/util/stl_util.h (+1/-2)
src/util/stream_util.cpp (+14/-0)
src/util/stream_util.h (+1/-1)
src/util/string/buf_rep.h (+1/-1)
src/util/string/default_rep.h (+2/-1)
src/util/string/ptr_rep.h (+2/-1)
src/util/string/rep_proxy.h (+1/-2)
src/util/string/rstring.h (+2/-1)
src/util/string_util.cpp (+2/-1)
src/util/string_util.h (+1/-1)
src/util/time_parse.cpp (+1/-1)
src/util/time_parse.h (+1/-1)
src/util/time_util.h (+1/-1)
src/util/unicode_util.cpp (+1/-1)
src/util/unordered_map.h (+2/-1)
src/util/unordered_set.h (+2/-1)
src/util/uri_util.cpp (+1/-1)
src/util/uri_util.h (+4/-2)
src/util/utf8_streambuf.cpp (+1/-1)
src/util/utf8_util.cpp (+4/-1)
src/util/utf8_util.h (+2/-1)
src/util/zorba_regex.h (+2/-1)
src/zorbatypes/URI.cpp (+0/-2)
src/zorbatypes/ft_token.cpp (+2/-1)
src/zorbatypes/ft_token.h (+1/-1)
src/zorbatypes/integer.cpp (+1/-1)
src/zorbautils/locale.cpp (+1/-1)
test/apitest.cpp (+8/-9)
test/driver/sax2testdriver.cpp (+34/-29)
test/driver/testdriver.cpp (+43/-44)
test/driver/updtestdriver.cpp (+52/-50)
test/unit/CMakeLists.txt (+0/-2)
test/unit/path_resolver.cpp (+0/-68)
test/unit/test_filesystempath.cpp (+0/-80)
test/unit/uri_file_decoding_test.cpp (+2/-2)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug-1180220
Reviewer Review Type Date Requested Status
Chris Hillery 2013-06-06 Approve on 2013-06-11
Matthias Brantner 2013-06-06 Approve on 2013-06-06
Paul J. Lucas Approve on 2013-06-05
Review via email: mp+167177@code.launchpad.net

Commit Message

Removed plethora of file classes; moved much of fs_util to the public API to take its place.

Description of the Change

Removed plethora of file classes; moved much of fs_util to the public API to take its place.

To post a comment you must log in.
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-03T23-40-21.931Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-04T16-43-15.194Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-04T20-19-05.33Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-04T23-20-14.642Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Paul J. Lucas (paul-lucas) :
review: Approve
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-05T00-34-07.697Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-05T04-36-11.699Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Chris Hillery (ceejatec) wrote :

FYI, these failures keep happening after the build when it calls "make fots-import". So you should be able to test that locally.

Chris Hillery (ceejatec) wrote :

This merge proposal was timing out, which is why it kept running the RQ over and over again. (Yes, the RQ should respond more gracefully to timeouts.) I've set it to "Needs Fixing" to stop it.

The problem tests seem to be xqts-xquery and xqtsx-xqx, not too surprisingly. In particular, based on lsof output from the testdriver_mt processes, they are getting stuck in an infinite loop while executing the test Functions/AllStringFunc/MatchStringFunc/MatchesFunc/caselessmatch15. I base this on the fact that the processes in question have an open file descriptor for build/test/rbkt/QueryResults/w3c_testsuite/XQuery/Functions/AllStringFunc/MatchStringFunc/MatchesFunc/caselessmatch15.err_0 , which I think should have been closed if the testcase hadn't hung. (The xqts-xqueryx testdriver_mt process has the same file only in .../w3c_testsuite/XQueryX/....)

Looking at that test case, I can't begin to guess why it would hang with your changes, but it seems pretty consistent.

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-05T08-36-15.066Z is finished. The
  final status was:

  13 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Chris Hillery (ceejatec) wrote :

Ok, I manually killed the testdriver_mt processes on the RQ box, which allowed the last run to submit its results to CDash. So in addition to the XQTS problems, you can see there are 11 other test failures to look at.

Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1180220-2013-06-06T00-35-08.319Z is finished. The final status was:

All tests succeeded!

Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve.

What are the changes in modules/ExternalModules.conf good for?

Paul J. Lucas (paul-lucas) wrote :

> What are the changes in modules/ExternalModules.conf good for?

Did you read Chris's only way to make incompatible changes affecting external modules e-mail? That's why. It's temporary because it's a chicken-and-egg problem.

review: Approve
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1180220-2013-06-07T05-03-17.543Z is finished. The final status was:

All tests succeeded!

Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 2 Approve, 1 Pending.

lp:~zorba-coders/zorba/bug-1180220 updated on 2013-06-07
11502. By Chris Hillery on 2013-06-07

Removed commented-out lines that only differed in removal of tags.

Chris Hillery (ceejatec) wrote :

1. What's the difference between include/zorba/internal and include/zorba/util?

2. Was it necessary/a good idea to move cxx_util.h and error_util.h into the set of shipped headers?

3. Why was cxx_util.h moved to internal/ and error_util.h to util/ ?

4. Have you done any testing on Windows? There are several #ifdef WIN32 changes. If necessary I could request Juan or Luis to test it out (would prefer Rodolfo but he's busy with website stuff).

review: Needs Information
Paul J. Lucas (paul-lucas) wrote :

> 1. What's the difference between include/zorba/internal and
> include/zorba/util?

Internal is for our use only. We make no claim that stuff in there will not either change or be removed at any time.

> 2. Was it necessary/a good idea to move cxx_util.h and error_util.h into the
> set of shipped headers?

Because they're necessary for fs_util.h.

> 3. Why was cxx_util.h moved to internal/ and error_util.h to util/ ?

Because cxx_util.h is a temporary measure until C++0x compilers are wide-spread and the file may disappear at any time; error_util.h will stick around (see #1 answer above).

> 4. Have you done any testing on Windows?

It's pretty much impossible for me to do that.

> There are several #ifdef WIN32
> changes. If necessary I could request Juan or Luis to test it out (would
> prefer Rodolfo but he's busy with website stuff).

You can, if you like.

lp:~zorba-coders/zorba/bug-1180220 updated on 2013-06-11
11503. By Paul J. Lucas on 2013-06-07

Merge from trunk.

11504. By Paul J. Lucas on 2013-06-07

Merge from trunk.

11505. By Paul J. Lucas on 2013-06-10

Merge from trunk.

11506. By Paul J. Lucas on 2013-06-10

Windows fixes.

11507. By Paul J. Lucas on 2013-06-11

Windows fix.

11508. By Paul J. Lucas on 2013-06-11

Windows fix.

11509. By Paul J. Lucas on 2013-06-11

Windows fix.

11510. By Paul J. Lucas on 2013-06-11

Merge from trunk.

11511. By Paul J. Lucas on 2013-06-11

Merge from trunk.

11512. By Paul J. Lucas on 2013-06-11

Windows fix.

Chris Hillery (ceejatec) wrote :

Juan reported some Windows compilation failures which are now fixed. There are a number of test failures but they seem to be the same set as without Paul's changes, so presumably no regressions.

review: Approve
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1180220-2013-06-11T23-06-19.773Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-06-11 15:47:07 +0000
3+++ ChangeLog 2013-06-11 16:49:27 +0000
4@@ -21,6 +21,7 @@
5 * Fixed bug #1188084 (fn-replace-42 failing)
6 * Fixed bug in hoisting through try-catch expr
7 * Fixed bug #1162631 (format-integer 'w' format of negative numbers)
8+ * Fixed bug #1180220 (Consolidate redundant path/file public APIs)
9 * Fixed bug #1103115 (Timezone units as hours are wrong)
10 * Fixed implementation of fn:deep-equal according to latest W3C spec.
11 * Must apply document ordering on the domain expression of a FOR clause, if
12
13=== modified file 'bin/path_util.cpp'
14--- bin/path_util.cpp 2013-02-07 17:24:36 +0000
15+++ bin/path_util.cpp 2013-06-11 16:49:27 +0000
16@@ -16,13 +16,13 @@
17
18 #include "path_util.h"
19
20-#include <stdlib.h>
21-//#include "zorba/zorba_string.h"
22-#include "zorba/util/path.h"
23+#include <cstdlib>
24+
25+#include <zorba/static_context.h>
26+#include <zorba/util/fs_util.h>
27
28 #include "util.h"
29 #include "zorbacmdproperties.h"
30-#include <zorba/static_context.h>
31
32 namespace zorba {
33
34@@ -54,28 +54,28 @@
35 std::string lPathStr;
36
37 // Compute the current working directory to append to all paths.
38- filesystem_path lCWD;
39+ std::string lCWD( fs::curdir() );
40
41 // setModulePaths() *overwrites* the URI path and lib path, so there's no
42 // sense in calling both. So if --module-path exists, just use it.
43 aProperties.getModulePath(lPathStr);
44 if (lPathStr.length() > 0) {
45 tokenizePath(lPathStr, lPath);
46- lPath.push_back(lCWD.get_path());
47+ lPath.push_back(lCWD);
48 aStaticCtx->setModulePaths(lPath);
49 }
50 else {
51 // Compute and set URI path
52 aProperties.getURIPath(lPathStr);
53 tokenizePath(lPathStr, lPath);
54- lPath.push_back(lCWD.get_path());
55+ lPath.push_back(lCWD);
56 aStaticCtx->setURIPath(lPath);
57 lPath.clear();
58
59 // Compute and set lib path
60 aProperties.getLibPath(lPathStr);
61 tokenizePath(lPathStr, lPath);
62- lPath.push_back(lCWD.get_path());
63+ lPath.push_back(lCWD);
64 aStaticCtx->setLibPath(lPath);
65 }
66 }
67
68=== modified file 'bin/zorbacmd.cpp'
69--- bin/zorbacmd.cpp 2013-05-28 00:58:27 +0000
70+++ bin/zorbacmd.cpp 2013-06-11 16:49:27 +0000
71@@ -30,7 +30,6 @@
72 #endif
73
74 #include <zorba/zorba.h>
75-#include <zorba/file.h>
76 #include <zorba/zorba_exception.h>
77 #include <zorba/xquery_exception.h>
78 #include <zorba/document_manager.h>
79@@ -41,8 +40,8 @@
80 #include <zorba/serialization_callback.h>
81 #include <zorba/audit.h>
82 #include <zorba/audit_scoped.h>
83-
84 #include <zorba/store_manager.h>
85+#include <zorba/util/fs_util.h>
86
87 //#define DO_AUDIT
88
89@@ -54,9 +53,6 @@
90 #include "util.h"
91 #include "path_util.h"
92
93-// For setting the base URI from the current directory
94-#include <zorba/util/path.h>
95-
96 // Timing utilities, including wall-clock timing
97 #include <zorba/util/time.h>
98
99@@ -77,8 +73,6 @@
100 "Copyright 2006-2009 The FLWOR Foundation.\n"
101 "License: Apache License 2.0: <http://www.apache.org/licenses/LICENSE-2.0>";
102
103-#define PATH_SEP (zorba::filesystem_path::get_directory_separator ())
104-
105 #ifndef ZORBA_NO_FULL_TEXT
106 OneToOneURIMapper theStopWordsMapper(EntityData::STOP_WORDS);
107 OneToOneURIMapper theThesaurusMapper(EntityData::THESAURUS);
108@@ -368,13 +362,13 @@
109 if(str.compare(0, strlen(file3), file3) == 0) {
110 fpath = str.substr(strlen(file3));
111 } else if(str.compare(0, strlen(file2), file2) == 0) {
112- fpath = PATH_SEP;
113+ fpath = fs::dir_separator;
114 fpath += str.substr(strlen(file2));
115 }
116 // replace all slash with backslash
117 std::string::size_type off=0;
118 while ((off=fpath.find('/', off)) != std::string::npos)
119- fpath.replace(off, 1, PATH_SEP);
120+ fpath.replace(off, 1, 1, fs::dir_separator);
121 return fpath;
122
123 #else // for UNIX
124@@ -639,14 +633,8 @@
125 removeOutputFileIfNeeded(const ZorbaCMDProperties& lProperties)
126 {
127 #ifdef ZORBA_WITH_FILE_ACCESS
128- if (lProperties.outputFile().size() > 0)
129- {
130- File_t lFile = zorba::File::createFile(lProperties.outputFile());
131- if (lFile->exists())
132- {
133- lFile->remove();
134- }
135- }
136+ if ( !lProperties.outputFile().empty() )
137+ fs::remove( lProperties.outputFile(), true );
138 #endif /* ZORBA_WITH_FILE_ACCESS */
139 }
140
141@@ -1021,7 +1009,7 @@
142 std::string configJvmClassPath;
143 globaproperties->getJVMClassPath(configJvmClassPath);
144 globaproperties->setJVMClassPath(cmdJvmClassPath +
145- filesystem_path::get_path_separator() + configJvmClassPath);
146+ fs::path_separator + configJvmClassPath);
147
148 // Start the engine
149
150@@ -1068,14 +1056,14 @@
151 //
152 std::string fURI = *lIter;
153 std::string fname = parseFileURI (properties.asFiles (), fURI);
154- zorba::filesystem_path path (fname);
155- bool asFile = ! fname.empty ();
156+ std::string path( fname );
157+ bool asFile = !fname.empty();
158 std::auto_ptr<std::istream> qfile;
159
160 if (asFile)
161 {
162- path.resolve_relative ();
163- qfile.reset(new std::ifstream (path.c_str ()));
164+ fs::make_absolute( path );
165+ qfile.reset( new std::ifstream( path.c_str() ) );
166 }
167 else
168 {
169@@ -1129,10 +1117,11 @@
170 {
171 // No user set base URI. Set the cwd to be used as base-uri in order
172 // to make the doc function doc("mydoc.xml") work
173- zorba::filesystem_path p;
174+ std::string p( fs::curdir() );
175 std::stringstream lTmp;
176 std::vector<std::string> lTokens;
177- Util::tokenize(p.c_str(), PATH_SEP, lTokens);
178+ std::string const delim( 1, fs::dir_separator );
179+ Util::tokenize(p.c_str(), delim, lTokens);
180
181 lTmp << "file://";
182 for (std::vector<std::string>::const_iterator lIter = lTokens.begin();
183@@ -1155,7 +1144,7 @@
184 zorba::XQuery_t lQuery = lZorbaInstance->createQuery();
185 if (asFile)
186 {
187- lQuery->setFileName(path.get_path());
188+ lQuery->setFileName(path);
189 }
190
191 lQuery->parse (*qfile);
192@@ -1178,7 +1167,7 @@
193 zorba::XQuery_t aQuery = lZorbaInstance->createQuery();
194 if (asFile)
195 {
196- aQuery->setFileName(path.get_path());
197+ aQuery->setFileName(path);
198 }
199
200 aQuery->parse(*qfile);
201@@ -1198,7 +1187,7 @@
202 int status = compileAndExecute(lZorbaInstance,
203 properties,
204 lStaticContext,
205- path.get_path(),
206+ path,
207 *qfile,
208 *lOutputStream,
209 queryTiming);
210@@ -1236,7 +1225,7 @@
211 }
212
213 std::auto_ptr<std::istream> lXQ(new std::ifstream(path.c_str()));
214- std::string lFileName(path.get_path());
215+ std::string lFileName(path);
216
217 zorba::XQuery_t lQuery;
218
219
220=== modified file 'include/zorba/api_shared_types.h'
221--- include/zorba/api_shared_types.h 2013-04-10 10:13:31 +0000
222+++ include/zorba/api_shared_types.h 2013-06-11 16:49:27 +0000
223@@ -16,75 +16,71 @@
224 #ifndef ZORBA_SHARED_TYPES_INCL_H
225 #define ZORBA_SHARED_TYPES_INCL_H
226
227-#include <memory>
228-
229 #include <zorba/config.h>
230 #include <zorba/smart_ptr.h>
231
232 namespace zorba {
233
234- class Zorba;
235- class XQuery;
236- class StaticContext;
237- class DynamicContext;
238- class XmlDataManager;
239- class DocumentManager;
240- class CollectionManager;
241- class StaticCollectionManager;
242- class ItemFactory;
243- class Iterator;
244- class StatelessExternalFunction;
245- class ExternalFunctionParameter;
246- class ExternalModule;
247- class TypeIdentifier;
248- class ItemSequence;
249- class Collection;
250- class Function;
251- class Annotation;
252- class SerializationCallback;
253- class File;
254- class DirectoryIterator;
255- class Serializer;
256- class ModuleInfo;
257-
258- class DiagnosticHandler;
259- class QueryLocation;
260- typedef SmartPtr<QueryLocation> QueryLocation_t;
261-
262+///////////////////////////////////////////////////////////////////////////////
263+
264+class Annotation;
265+class Collection;
266+class CollectionManager;
267+class DiagnosticHandler;
268+class DocumentManager;
269+class DynamicContext;
270+class ExternalFunctionParameter;
271+class ExternalModule;
272+class Function;
273+class ItemFactory;
274+class ItemSequence;
275+class Iterator;
276+class ModuleInfo;
277+class QueryLocation;
278+class SerializationCallback;
279+class Serializer;
280+class StatelessExternalFunction;
281+class StaticCollectionManager;
282+class StaticContext;
283 #ifndef ZORBA_NO_FULL_TEXT
284- class StemmerProvider;
285- class TokenizerProvider;
286+class StemmerProvider;
287+class TokenizerProvider;
288 #endif /* ZORBA_NO_FULL_TEXT */
289-
290- // smart pointers
291- typedef zorba::SmartPtr<XQuery> XQuery_t;
292- typedef zorba::SmartPtr<StaticContext> StaticContext_t;
293- typedef zorba::SmartPtr<Iterator> Iterator_t;
294- typedef zorba::SmartPtr<TypeIdentifier> TypeIdentifier_t;
295- typedef zorba::SmartPtr<Collection> Collection_t;
296- typedef zorba::SmartPtr<Function> Function_t;
297- typedef zorba::SmartPtr<Annotation> Annotation_t;
298- typedef zorba::SmartPtr<File> File_t;
299- typedef zorba::SmartPtr<DirectoryIterator> DirectoryIterator_t;
300- typedef zorba::SmartPtr<Serializer> Serializer_t;
301- typedef zorba::SmartPtr<ItemSequence> ItemSequence_t;
302- typedef zorba::SmartPtr<ModuleInfo> ModuleInfo_t;
303-
304- // data handlers
305- class Item;
306- class String;
307-
308- // uri resolvers
309- class URIMapper;
310- class Resource;
311- class URLResolver;
312-
313- namespace audit {
314- class Provider;
315- class Event;
316- class ScopedRecord;
317- }
318-
319-} /* namespace zorba */
320-#endif
321+class TypeIdentifier;
322+class XmlDataManager;
323+class XQuery;
324+class Zorba;
325+
326+// smart pointers
327+typedef SmartPtr<Annotation> Annotation_t;
328+typedef SmartPtr<Collection> Collection_t;
329+typedef SmartPtr<Function> Function_t;
330+typedef SmartPtr<ItemSequence> ItemSequence_t;
331+typedef SmartPtr<Iterator> Iterator_t;
332+typedef SmartPtr<ModuleInfo> ModuleInfo_t;
333+typedef SmartPtr<QueryLocation> QueryLocation_t;
334+typedef SmartPtr<Serializer> Serializer_t;
335+typedef SmartPtr<StaticContext> StaticContext_t;
336+typedef SmartPtr<TypeIdentifier> TypeIdentifier_t;
337+typedef SmartPtr<XQuery> XQuery_t;
338+
339+// data handlers
340+class Item;
341+class String;
342+
343+// uri resolvers
344+class URIMapper;
345+class Resource;
346+class URLResolver;
347+
348+namespace audit {
349+ class Provider;
350+ class Event;
351+ class ScopedRecord;
352+}
353+
354+///////////////////////////////////////////////////////////////////////////////
355+
356+} // namespace zorba
357+#endif /* ZORBA_SHARED_TYPES_INCL_H */
358 /* vim:set et sw=2 ts=2: */
359
360=== modified file 'include/zorba/base64_stream.h'
361--- include/zorba/base64_stream.h 2013-02-12 03:55:18 +0000
362+++ include/zorba/base64_stream.h 2013-06-11 16:49:27 +0000
363@@ -20,6 +20,7 @@
364 #include <streambuf>
365
366 #include <zorba/config.h>
367+#include <zorba/internal/cxx_util.h>
368 #include <zorba/internal/streambuf.h>
369
370 namespace zorba {
371@@ -174,7 +175,7 @@
372 void detach( std::basic_ios<charT,Traits> &ios ) {
373 int const index = internal::base64::get_streambuf_index();
374 if ( streambuf *const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {
375- ios.pword( index ) = 0;
376+ ios.pword( index ) = nullptr;
377 ios.rdbuf( buf->orig_streambuf() );
378 internal::dealloc_streambuf( buf );
379 }
380
381=== removed file 'include/zorba/file.h'
382--- include/zorba/file.h 2013-04-19 22:25:21 +0000
383+++ include/zorba/file.h 1970-01-01 00:00:00 +0000
384@@ -1,100 +0,0 @@
385-/*
386- * Copyright 2006-2008 The FLWOR Foundation.
387- *
388- * Licensed under the Apache License, Version 2.0 (the "License");
389- * you may not use this file except in compliance with the License.
390- * You may obtain a copy of the License at
391- *
392- * http://www.apache.org/licenses/LICENSE-2.0
393- *
394- * Unless required by applicable law or agreed to in writing, software
395- * distributed under the License is distributed on an "AS IS" BASIS,
396- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
397- * See the License for the specific language governing permissions and
398- * limitations under the License.
399- */
400-#ifndef ZORBA_FILE_API_H
401-#define ZORBA_FILE_API_H
402-
403-#include <string>
404-
405-#include <zorba/config.h>
406-#include <zorba/api_shared_types.h>
407-
408-namespace zorba {
409-
410- /** \brief This class is the representation of file system file.
411- *
412- * ...
413- */
414- class ZORBA_DLL_PUBLIC DirectoryIterator : public SmartObject
415- {
416- public:
417-
418- virtual ~DirectoryIterator() {}
419-
420- virtual bool next(std::string& aPathStr) const = 0;
421- /** \brief Rewind the file find iterator
422- */
423- virtual void reset() = 0;
424- };
425-
426-
427- /** \brief This class is the representation of file system file.
428- *
429- * ...
430- */
431- class ZORBA_DLL_PUBLIC File : public SmartObject
432- {
433- public: // constructors
434-
435- virtual ~File() {}
436-
437- static File_t createFile(const std::string& path);
438-
439- static const char* getDirectorySeparator();
440-
441- static const char* getPathSeparator();
442-
443- public: // type, enums
444-
445-#ifdef WIN32
446- typedef __int64 FileSize_t;
447-#else
448- typedef int64_t FileSize_t;
449-#endif
450-
451-
452- public: // public methods
453-
454- virtual const std::string getFilePath() const = 0;
455- virtual const std::string getFileUri() const = 0;
456-
457- virtual bool isDirectory( bool follow_symlinks = true ) const = 0;
458- virtual bool isFile( bool follow_symlinks = true ) const = 0;
459- virtual bool isLink() const = 0;
460- virtual bool isVolume( bool follow_symlinks = true ) const = 0;
461- virtual bool isInvalid() const = 0; // deprecated
462- virtual bool exists( bool follow_symlinks = true ) const = 0;
463-
464- virtual void remove() = 0;
465- virtual bool create() = 0;
466- virtual bool rename(std::string const& newpath) = 0;
467-
468- virtual FileSize_t getSize() const = 0;
469-
470- virtual void mkdir(bool recursive) = 0;
471-
472- virtual DirectoryIterator_t files() const = 0;
473-
474- virtual void openInputStream(std::ifstream& aInStream, bool binary, bool trimByteOrderMark) const = 0;
475- virtual void openOutputStream(std::ofstream& aOutStream, bool binary, bool append) const = 0;
476-
477- virtual time_t lastModified() const = 0;
478-
479- };
480-
481-} /* namespace zorba */
482-
483-#endif
484-/* vim:set et sw=2 ts=2: */
485
486=== renamed file 'src/util/cxx_util.h' => 'include/zorba/internal/cxx_util.h'
487--- src/util/cxx_util.h 2013-02-07 17:24:36 +0000
488+++ include/zorba/internal/cxx_util.h 2013-06-11 16:49:27 +0000
489@@ -14,8 +14,8 @@
490 * limitations under the License.
491 */
492
493-#ifndef ZORBA_CXX_UTIL_H
494-#define ZORBA_CXX_UTIL_H
495+#ifndef ZORBA_INTERNAL_CXX_UTIL_H
496+#define ZORBA_INTERNAL_CXX_UTIL_H
497
498 #include <zorba/config.h>
499
500@@ -24,6 +24,7 @@
501 #ifndef ZORBA_CXX_NULLPTR
502
503 namespace zorba {
504+namespace internal {
505
506 /**
507 * A \c nullptr type.
508@@ -45,6 +46,7 @@
509 void operator&() const; // whose address can't be taken
510 };
511
512+} // namespace internal
513 } // namespace zorba
514
515 /**
516@@ -55,7 +57,7 @@
517 * Bjarne's paper has a slight performance penalty.
518 */
519 ZORBA_DLL_PUBLIC
520-extern zorba::nullptr_type const zorba_nullptr;
521+extern zorba::internal::nullptr_type const zorba_nullptr;
522
523 #define nullptr ::zorba_nullptr
524
525@@ -78,5 +80,5 @@
526
527 ///////////////////////////////////////////////////////////////////////////////
528
529-#endif /* ZORBA_CXX_UTIL_H */
530+#endif /* ZORBA_INTERNAL_CXX_UTIL_H */
531 /* vim:set et sw=2 ts=2: */
532
533=== modified file 'include/zorba/internal/unique_ptr.h'
534--- include/zorba/internal/unique_ptr.h 2013-02-07 17:24:36 +0000
535+++ include/zorba/internal/unique_ptr.h 2013-06-11 16:49:27 +0000
536@@ -25,6 +25,7 @@
537 #else
538
539 #include <algorithm> /* for swap() */
540+#include "cxx_util.h"
541 #include "type_traits.h"
542 #include "ztd.h"
543
544@@ -159,7 +160,8 @@
545 */
546 template<typename U>
547 default_delete( default_delete<U> const&,
548- typename enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type* = 0 )
549+ typename enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type*
550+ = nullptr )
551 {
552 }
553
554@@ -218,7 +220,7 @@
555 *
556 * @param p A pointer to the object to point to, if any.
557 */
558- explicit unique_ptr( pointer p = 0 ) throw() : storage_( p ) {
559+ explicit unique_ptr( pointer p = nullptr ) throw() : storage_( p ) {
560 }
561
562 /**
563@@ -266,7 +268,7 @@
564 !ZORBA_TR1_NS::is_reference<D>::value ||
565 ZORBA_TR1_NS::is_same<D,E>::value
566 )
567- >::type* = 0
568+ >::type* = nullptr
569 ) :
570 storage_( p.release(), move<D>( p.get_deleter() ) )
571 {
572@@ -374,7 +376,7 @@
573 */
574 pointer release() throw() {
575 pointer const temp = get();
576- storage_.ptr_ = 0;
577+ storage_.ptr_ = nullptr;
578 return temp;
579 }
580
581@@ -385,7 +387,7 @@
582 *
583 * @param p The new pointer value, if any.
584 */
585- void reset( pointer p = 0 ) throw() {
586+ void reset( pointer p = nullptr ) throw() {
587 if ( p != storage_.ptr_ ) {
588 call_deleter();
589 storage_.ptr_ = p;
590@@ -462,7 +464,7 @@
591 typedef T* pointer;
592 typedef D deleter_type;
593
594- explicit unique_ptr( pointer p = 0 ) throw() : storage_( p ) {
595+ explicit unique_ptr( pointer p = nullptr ) throw() : storage_( p ) {
596 }
597
598 unique_ptr( pointer p, deleter_reference d ) : storage_( p, d ) {
599@@ -496,11 +498,11 @@
600
601 pointer release() throw() {
602 pointer const temp = get();
603- storage_.ptr_ = 0;
604+ storage_.ptr_ = nullptr;
605 return temp;
606 }
607
608- void reset( pointer p = 0 ) throw() {
609+ void reset( pointer p = nullptr ) throw() {
610 if ( p != storage_.ptr_ ) {
611 call_deleter();
612 storage_.ptr_ = p;
613
614=== modified file 'include/zorba/internal/ztd.h'
615--- include/zorba/internal/ztd.h 2013-05-09 00:48:27 +0000
616+++ include/zorba/internal/ztd.h 2013-06-11 16:49:27 +0000
617@@ -24,6 +24,7 @@
618
619 #include <zorba/config.h>
620
621+#include "cxx_util.h"
622 #include "type_traits.h"
623
624 ///////////////////////////////////////////////////////////////////////////////
625@@ -210,7 +211,8 @@
626 template<typename U>
627 destroy_delete( destroy_delete<U> const&,
628 typename
629- std::enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type* = 0 )
630+ std::enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type*
631+ = nullptr )
632 {
633 }
634
635
636=== modified file 'include/zorba/stemmer.h'
637--- include/zorba/stemmer.h 2013-02-07 17:24:36 +0000
638+++ include/zorba/stemmer.h 2013-06-11 16:49:27 +0000
639@@ -21,6 +21,7 @@
640
641 #ifndef ZORBA_NO_FULL_TEXT
642
643+#include <zorba/internal/cxx_util.h>
644 #include <zorba/internal/unique_ptr.h>
645 #include <zorba/internal/ztd.h>
646 #include <zorba/locale.h>
647@@ -98,7 +99,7 @@
648 * \a lang.
649 */
650 virtual bool getStemmer( locale::iso639_1::type lang,
651- Stemmer::ptr *s = 0 ) const = 0;
652+ Stemmer::ptr *s = nullptr ) const = 0;
653 };
654
655 ///////////////////////////////////////////////////////////////////////////////
656
657=== modified file 'include/zorba/thesaurus.h'
658--- include/zorba/thesaurus.h 2013-02-07 17:24:36 +0000
659+++ include/zorba/thesaurus.h 2013-06-11 16:49:27 +0000
660@@ -21,6 +21,7 @@
661
662 #ifndef ZORBA_NO_FULL_TEXT
663
664+#include <zorba/internal/cxx_util.h>
665 #include <zorba/internal/unique_ptr.h>
666 #include <zorba/internal/ztd.h>
667 #include <zorba/locale.h>
668@@ -128,7 +129,7 @@
669 * \a lang.
670 */
671 virtual bool getThesaurus( locale::iso639_1::type lang,
672- Thesaurus::ptr *t = 0 ) const = 0;
673+ Thesaurus::ptr *t = nullptr ) const = 0;
674 };
675
676 ///////////////////////////////////////////////////////////////////////////////
677
678=== modified file 'include/zorba/tokenizer.h'
679--- include/zorba/tokenizer.h 2013-02-07 17:24:36 +0000
680+++ include/zorba/tokenizer.h 2013-06-11 16:49:27 +0000
681@@ -21,9 +21,10 @@
682 #include <vector>
683
684 #include <zorba/config.h>
685-#include <zorba/locale.h>
686+#include <zorba/internal/cxx_util.h>
687 #include <zorba/internal/unique_ptr.h>
688 #include <zorba/internal/ztd.h>
689+#include <zorba/locale.h>
690
691 namespace zorba {
692
693@@ -101,7 +102,7 @@
694 virtual void token( char const *utf8_s, size_type utf8_len,
695 locale::iso639_1::type lang,
696 size_type token_no, size_type sent_no,
697- size_type para_no, Item const *item = 0 ) = 0;
698+ size_type para_no, Item const *item = nullptr ) = 0;
699 };
700
701 /////////////////////////////////////////////////////////////////////////////
702@@ -200,7 +201,8 @@
703 */
704 virtual void tokenize_string( char const *utf8_s, size_type utf8_len,
705 locale::iso639_1::type lang, bool wildcards,
706- Callback &callback, Item const *item = 0 ) = 0;
707+ Callback &callback,
708+ Item const *item = nullptr ) = 0;
709
710 /////////////////////////////////////////////////////////////////////////////
711
712@@ -295,8 +297,8 @@
713 * \a lang.
714 */
715 virtual bool getTokenizer( locale::iso639_1::type lang,
716- Tokenizer::State *state = 0,
717- Tokenizer::ptr *t = 0 ) const = 0;
718+ Tokenizer::State *state = nullptr,
719+ Tokenizer::ptr *t = nullptr ) const = 0;
720 };
721
722 ///////////////////////////////////////////////////////////////////////////////
723
724=== modified file 'include/zorba/transcode_stream.h'
725--- include/zorba/transcode_stream.h 2013-02-26 04:12:43 +0000
726+++ include/zorba/transcode_stream.h 2013-06-11 16:49:27 +0000
727@@ -18,6 +18,7 @@
728 #define ZORBA_TRANSCODE_STREAM_API_H
729
730 #include <zorba/config.h>
731+#include <zorba/internal/cxx_util.h>
732 #include <zorba/internal/streambuf.h>
733 #include <zorba/internal/unique_ptr.h>
734
735@@ -164,7 +165,7 @@
736 void detach( std::basic_ios<charT,Traits> &ios ) {
737 int const index = internal::transcode::get_streambuf_index();
738 if ( streambuf *const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {
739- ios.pword( index ) = 0;
740+ ios.pword( index ) = nullptr;
741 ios.rdbuf( buf->orig_streambuf() );
742 internal::dealloc_streambuf( buf );
743 }
744
745=== modified file 'include/zorba/user_exception.h'
746--- include/zorba/user_exception.h 2013-02-07 17:24:36 +0000
747+++ include/zorba/user_exception.h 2013-06-11 16:49:27 +0000
748@@ -21,6 +21,7 @@
749
750 #include <zorba/api_shared_types.h>
751 #include <zorba/error.h>
752+#include <zorba/internal/cxx_util.h>
753 #include <zorba/xquery_exception.h>
754
755 namespace zorba {
756@@ -60,7 +61,7 @@
757 ZorbaException::line_type raise_line,
758 char const *ns, char const *prefix, char const *localname,
759 char const *description, diagnostic::location const &loc,
760- error_object_type *error_object = 0 );
761+ error_object_type *error_object = nullptr );
762
763 /**
764 * \internal
765@@ -83,7 +84,7 @@
766 ZorbaException::line_type raise_line,
767 Error const &error, char const *description,
768 diagnostic::location const &loc,
769- error_object_type *error_object = 0 );
770+ error_object_type *error_object = nullptr );
771
772 } // namespace internal
773
774@@ -369,7 +370,7 @@
775 make_user_exception( char const *raise_file,
776 ZorbaException::line_type raise_line,
777 Error const &error, String const &description,
778- error_object_type *error_object = 0 );
779+ error_object_type *error_object = nullptr );
780
781 ///////////////////////////////////////////////////////////////////////////////
782
783
784=== renamed file 'src/util/error_util.h' => 'include/zorba/util/error_util.h'
785--- src/util/error_util.h 2013-05-08 01:05:04 +0000
786+++ include/zorba/util/error_util.h 2013-06-11 16:49:27 +0000
787@@ -15,10 +15,13 @@
788 */
789
790 #pragma once
791-#ifndef ZORBA_ERROR_UTIL_H
792-#define ZORBA_ERROR_UTIL_H
793+#ifndef ZORBA_API_ERROR_UTIL_H
794+#define ZORBA_API_ERROR_UTIL_H
795
796 #include <zorba/config.h>
797+#include <zorba/internal/cxx_util.h>
798+#include <zorba/internal/type_traits.h>
799+#include <zorba/internal/ztd.h>
800
801 #include <stdexcept>
802 #ifndef WIN32
803@@ -27,9 +30,6 @@
804 # include <windows.h>
805 #endif /* WIN32 */
806
807-#include "cxx_util.h"
808-#include "string_util.h"
809-
810 namespace zorba {
811 namespace os_error {
812
813@@ -47,7 +47,7 @@
814 * An %exception is-a std::runtime_error for reporting errors with operating
815 * system or library functions.
816 */
817-class exception : public std::runtime_error {
818+class ZORBA_DLL_PUBLIC exception : public std::runtime_error {
819 public:
820 /**
821 * Constructs an %exception.
822@@ -60,11 +60,7 @@
823 * the operating system error string; if empty, no error string is used.
824 */
825 exception( char const *function, char const *path,
826- char const *err_string = nullptr ) :
827- std::runtime_error( make_what( function, path, err_string ) ),
828- function_( function ), path_( path )
829- {
830- }
831+ char const *err_string = nullptr );
832
833 /**
834 * Destroys an %exception.
835@@ -90,9 +86,6 @@
836 }
837
838 protected:
839- static std::string make_what( char const *function, char const *path,
840- char const *err_string = nullptr );
841-
842 std::string function_;
843 std::string path_;
844 };
845@@ -106,6 +99,7 @@
846 * @param err_string The error string.
847 * @return Returns said error string.
848 */
849+ZORBA_DLL_PUBLIC
850 std::string format_err_string( char const *function, char const *err_string );
851
852 /**
853@@ -116,6 +110,7 @@
854 * @param err_string The error string.
855 * @return Returns said error string.
856 */
857+ZORBA_DLL_PUBLIC
858 std::string format_err_string( char const *function, code_type code,
859 char const *err_string );
860
861@@ -139,6 +134,7 @@
862 * @param code The operating system error code.
863 * @return Returns said error string.
864 */
865+ZORBA_DLL_PUBLIC
866 std::string get_err_string( char const *function,
867 code_type code = get_err_code() );
868
869@@ -170,8 +166,7 @@
870
871 } // namespace os_error
872 } // namespace zorba
873-
874-#endif /* ZORBA_ERROR_UTIL_H */
875+#endif /* ZORBA_API_ERROR_UTIL_H */
876 /*
877 * Local variables:
878 * mode: c++
879
880=== removed file 'include/zorba/util/file.h'
881--- include/zorba/util/file.h 2013-04-19 22:25:21 +0000
882+++ include/zorba/util/file.h 1970-01-01 00:00:00 +0000
883@@ -1,122 +0,0 @@
884-/*
885- * Copyright 2006-2008 The FLWOR Foundation.
886- *
887- * Licensed under the Apache License, Version 2.0 (the "License");
888- * you may not use this file except in compliance with the License.
889- * You may obtain a copy of the License at
890- *
891- * http://www.apache.org/licenses/LICENSE-2.0
892- *
893- * Unless required by applicable law or agreed to in writing, software
894- * distributed under the License is distributed on an "AS IS" BASIS,
895- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
896- * See the License for the specific language governing permissions and
897- * limitations under the License.
898- */
899-
900-#ifndef ZORBA_FILE_H
901-#define ZORBA_FILE_H
902-
903-#ifndef WIN32
904-#include <stdint.h>
905-#endif
906-
907-#include <cstdio>
908-#include <string>
909-#include <time.h>
910-#include <vector>
911-
912-#include <zorba/config.h>
913-#include <zorba/file.h>
914-#include <zorba/util/path.h>
915-
916-namespace zorba {
917-
918-class ZORBA_DLL_PUBLIC file : public filesystem_path
919-{
920-public:
921-
922- enum filetype {
923- type_invalid,
924- type_non_existent,
925- type_directory,
926- type_link,
927- type_file,
928- type_volume,
929- type_other
930- };
931-
932- typedef zorba::File::FileSize_t file_size_t;
933-
934-protected:
935- filetype do_stat( bool follow_symlinks = true, file_size_t *size = 0 ) const;
936-
937-public:
938- file(const filesystem_path &path, int flags = 0);
939-
940-public: // common methods
941- void set_path(std::string const& _path ) { *((filesystem_path *) this) = _path; }
942- void set_filetype(filetype) { /* do nothing */ } // deprecated
943-
944- filetype get_filetype( bool follow_symlinks = true ) const {
945- return do_stat( follow_symlinks );
946- }
947-
948- bool is_directory( bool follow_symlinks = true ) const {
949- return do_stat( follow_symlinks ) == type_directory;
950- }
951-
952- bool is_file( bool follow_symlinks = true ) const {
953- return do_stat( follow_symlinks ) == type_file;
954- }
955-
956- bool is_link() const {
957- return do_stat( false ) == type_link;
958- }
959-
960- bool is_volume( bool follow_symlinks = true ) const {
961- return do_stat( follow_symlinks ) == type_volume;
962- }
963-
964- bool is_invalid() const { // deprecated
965- return false;
966- }
967-
968- bool exists( bool follow_symlinks = true ) const {
969- return do_stat( follow_symlinks ) != type_non_existent;
970- }
971-
972- time_t lastModified() const;
973-
974-public: // file methods
975- void create();
976- void remove(bool ignore = true);
977- void rename(std::string const& newpath);
978-
979- file_size_t get_size() const {
980- file_size_t size;
981- do_stat( true, &size );
982- return size;
983- }
984-
985-public: // directory methods
986- void mkdir();
987- void deep_mkdir();
988- void rmdir(bool ignore = true);
989- void lsdir(std::vector<std::string> &list);
990-#ifndef _WIN32_WCE
991- void chdir();
992-#endif
993-
994- bool is_empty() const { return get_size() == 0; }
995-};
996-
997-
998-} // namespace zorba
999-#endif /* ZORBA_FILE_H */
1000-/*
1001- * Local variables:
1002- * mode: c++
1003- * End:
1004- */
1005-/* vim:set et sw=2 ts=2: */
1006
1007=== added file 'include/zorba/util/fs_util.h'
1008--- include/zorba/util/fs_util.h 1970-01-01 00:00:00 +0000
1009+++ include/zorba/util/fs_util.h 2013-06-11 16:49:27 +0000
1010@@ -0,0 +1,627 @@
1011+/*
1012+ * Copyright 2006-2008 The FLWOR Foundation.
1013+ *
1014+ * Licensed under the Apache License, Version 2.0 (the "License");
1015+ * you may not use this file except in compliance with the License.
1016+ * You may obtain a copy of the License at
1017+ *
1018+ * http://www.apache.org/licenses/LICENSE-2.0
1019+ *
1020+ * Unless required by applicable law or agreed to in writing, software
1021+ * distributed under the License is distributed on an "AS IS" BASIS,
1022+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1023+ * See the License for the specific language governing permissions and
1024+ * limitations under the License.
1025+ */
1026+
1027+#ifndef ZORBA_API_FS_UTIL_H
1028+#define ZORBA_API_FS_UTIL_H
1029+
1030+// standard
1031+#include <cctype>
1032+#include <iostream>
1033+#include <string>
1034+#ifdef WIN32
1035+# include <windows.h>
1036+#else
1037+# include <dirent.h>
1038+# include <sys/types.h> /* for off_t */
1039+#endif /* WIN32 */
1040+
1041+#ifndef MAX_PATH
1042+/**
1043+ * Maximum path length. This is defined under Windows to be 1024. There is no
1044+ * equivalent constant/macro for *nix systems, so simply borrow Windows' value.
1045+ */
1046+#define MAX_PATH 1024
1047+#endif /* MAX_PATH */
1048+
1049+// Zorba
1050+#include <zorba/config.h>
1051+#include <zorba/internal/cxx_util.h>
1052+#include <zorba/internal/ztd.h>
1053+#include <zorba/util/error_util.h>
1054+
1055+namespace zorba {
1056+namespace fs {
1057+
1058+////////// Exceptions /////////////////////////////////////////////////////////
1059+
1060+typedef os_error::exception exception;
1061+
1062+////////// constants //////////////////////////////////////////////////////////
1063+
1064+#ifdef WIN32
1065+char const dir_separator = '\\';
1066+char const path_separator = ';';
1067+#else
1068+char const dir_separator = '/';
1069+char const path_separator = ':';
1070+#endif /* WIN32 */
1071+
1072+////////// types //////////////////////////////////////////////////////////////
1073+
1074+/**
1075+ * File size type.
1076+ */
1077+#ifdef WIN32
1078+typedef __int64 size_type;
1079+#else
1080+typedef off_t size_type;
1081+#endif /* WIN32 */
1082+
1083+/**
1084+ * File type.
1085+ */
1086+enum type {
1087+ non_existent,
1088+ directory,
1089+ file,
1090+ link,
1091+ volume,
1092+ other // named pipe, character/block special, socket, etc.
1093+};
1094+extern char const *const type_string[];
1095+
1096+/**
1097+ * Emits the string representation of a file type to the given ostream.
1098+ *
1099+ * @param o The ostream to emit to.
1100+ * @param t The file type to emit.
1101+ * @return Returns \a o.
1102+ */
1103+inline std::ostream& operator<<( std::ostream &o, type t ) {
1104+ return o << type_string[ t ];
1105+}
1106+
1107+////////// Windows ////////////////////////////////////////////////////////////
1108+
1109+#ifdef WIN32
1110+namespace win32 {
1111+
1112+// Do not use this function directly.
1113+ZORBA_DLL_PUBLIC
1114+void make_absolute_impl( char const *path, char *abs_path );
1115+
1116+} // namespace win32
1117+#endif /* WIN32 */
1118+
1119+////////// Directory //////////////////////////////////////////////////////////
1120+
1121+/**
1122+ * Gets the current directory.
1123+ *
1124+ * @return Returns said directory.
1125+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR if it
1126+ * fails.
1127+ */
1128+ZORBA_DLL_PUBLIC
1129+std::string curdir();
1130+
1131+#ifdef ZORBA_WITH_FILE_ACCESS
1132+
1133+/**
1134+ * Creates a directory.
1135+ *
1136+ * @param path The full path of the directory to create.
1137+ * @throws fs::exception if the creation fails.
1138+ */
1139+ZORBA_DLL_PUBLIC
1140+void mkdir( char const *path );
1141+
1142+/**
1143+ * Creates a directory.
1144+ *
1145+ * @tparam PathStringType The \a path string type.
1146+ * @param path The full path of the directory to create.
1147+ * @throws fs::exception if the creation fails.
1148+ */
1149+template<class PathStringType> inline
1150+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),void>::type
1151+mkdir( PathStringType const &path ) {
1152+ mkdir( path.c_str() );
1153+}
1154+
1155+#endif /* ZORBA_WITH_FILE_ACCESS */
1156+
1157+////////// File deletion //////////////////////////////////////////////////////
1158+
1159+#ifdef ZORBA_WITH_FILE_ACCESS
1160+
1161+/**
1162+ * Removes the given file or directory.
1163+ *
1164+ * @param path The full path of the file or directory to remove.
1165+ * @param ignore_not_found If \c true, a non-existant \a path will not throw an
1166+ * exception.
1167+ * @return Returns \c true if removal succeeds and \c false if it fails and
1168+ * \a ignore_not_found is \c true.
1169+ * @throws fs::exception if the removal fails unless \a path is non-existant
1170+ * and \a ignore_not_found is \c true.
1171+ */
1172+ZORBA_DLL_PUBLIC
1173+bool remove( char const *path, bool ignore_not_found = false );
1174+
1175+/**
1176+ * Removes the given file or directory.
1177+ *
1178+ * @tparam PathStringType The \a path string type.
1179+ * @param path The full path of the file or directory to remove.
1180+ * @param ignore_not_found If \c true, a non-existant \a path will not throw an
1181+ * exception.
1182+ * @return Returns \c true if removal succeeds and \c false if it fails and
1183+ * \a ignore_not_found is \c true.
1184+ * @throws fs::exception if the removal fails unless \a path is non-existant
1185+ * and \a ignore_not_found is \c true.
1186+ */
1187+template<class PathStringType> inline
1188+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),bool>::type
1189+remove( PathStringType const &path, bool ignore_not_found = false ) {
1190+ return remove( path.c_str(), ignore_not_found );
1191+}
1192+
1193+#endif /* ZORBA_WITH_FILE_ACCESS */
1194+
1195+////////// File information ///////////////////////////////////////////////////
1196+
1197+/**
1198+ * Checks whether the given path is an absolute path.
1199+ *
1200+ * @param path The full path to check.
1201+ * @return Returns \c true only if the path is absolute.
1202+ */
1203+inline bool is_absolute( char const *path ) {
1204+#ifndef WIN32
1205+ return path[0] == '/';
1206+#else
1207+ //
1208+ // No, this should NOT also check for '/'. The path should have been
1209+ // normalized for Windows first, i.e., have '/' replaced by '\'.
1210+ //
1211+ return isalpha( path[0] ) && path[1] == ':' && path[2] == '\\';
1212+#endif /* WIN32 */
1213+}
1214+
1215+/**
1216+ * Checks whether the given path is an absolute path.
1217+ *
1218+ * @tparam PathStringType The \a path string type.
1219+ * @param path The full path to check.
1220+ * @return Returns \c true only if the path is absolute.
1221+ */
1222+template<class PathStringType> inline
1223+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),bool>::type
1224+is_absolute( PathStringType const &path ) {
1225+ return is_absolute( path.c_str() );
1226+}
1227+
1228+/**
1229+ * Gets the base name of the given path name, i.e., the file name without the
1230+ * path leading up to it.
1231+ *
1232+ * @param path The full path to get the base name of.
1233+ * @return Returns the base name. Note that if \a path is just a file name,
1234+ * then returns \a path.
1235+ */
1236+inline char const* base_name( char const *path ) {
1237+ char const *const sep = ::strrchr( path, dir_separator );
1238+ return sep && sep[1] ? sep + 1 : path;
1239+}
1240+
1241+/**
1242+ * Gets the base name of the given path name, i.e., the file name without the
1243+ * path leading up to it.
1244+ *
1245+ * @tparam PathStringType The \a path string type.
1246+ * @param path The full path to get the base name of.
1247+ * @return Returns the base name. If \a path is just a file name, returns
1248+ * \a path.
1249+ */
1250+template<class PathStringType> inline
1251+typename std::enable_if<ZORBA_IS_STRING(PathStringType),PathStringType>::type
1252+base_name( PathStringType const &path ) {
1253+ typename PathStringType::size_type const pos = path.rfind( dir_separator );
1254+ return pos != PathStringType::npos && pos < path.size() - 1 ?
1255+ path.substr( pos + 1 ) : path;
1256+}
1257+
1258+/**
1259+ * Gets the directory name of the given path name, i.e., the path up to but not
1260+ * including the last path component.
1261+ *
1262+ * @param path The path to get the directory name of.
1263+ * @return Returns the direcory path. If \a path is just a file name, returns
1264+ * <code>'.'</code>.
1265+ */
1266+inline std::string dir_name( char const *path ) {
1267+ if ( char const *const sep = ::strrchr( path, dir_separator ) )
1268+ return sep == path ?
1269+ std::string( 1, dir_separator ) : std::string( path, sep );
1270+ return std::string( 1, '.' );
1271+}
1272+
1273+/**
1274+ * Gets the directory name of the given path name, i.e., the path up to but not
1275+ * including the last path component.
1276+ *
1277+ * @tparam PathStringType The \a path string type.
1278+ * @param path The path to get the directory name of.
1279+ * @return Returns the direcory path. If \a path is just a file name, returns
1280+ * <code>'.'</code>.
1281+ */
1282+template<class PathStringType> inline
1283+typename std::enable_if<ZORBA_IS_STRING(PathStringType),PathStringType>::type
1284+dir_name( PathStringType const &path ) {
1285+ typename PathStringType::size_type const pos = path.rfind( dir_separator );
1286+ if ( pos == PathStringType::npos )
1287+ return PathStringType( 1, '.' );
1288+ if ( pos == 0 ) // e.g., /foo
1289+ return PathStringType( 1, dir_separator );
1290+#ifdef WIN32
1291+ if ( pos == 2 && is_absolute( path ) )
1292+ return path.substr( 0, 3 );
1293+#endif /* WIN32 */
1294+ return path.substr( 0, pos );
1295+}
1296+
1297+#ifdef ZORBA_WITH_FILE_ACCESS
1298+
1299+/**
1300+ * File information for use with get_type().
1301+ */
1302+struct info {
1303+ time_t mtime; ///< file's last modification time (in seconds since epoch)
1304+ size_type size; ///< file's size in bytes
1305+ fs::type type; ///< file's type
1306+};
1307+
1308+/**
1309+ * Gets the type of the given file.
1310+ *
1311+ * @param path The full path to check.
1312+ * @param follow_symlink If \c true, follows symbolic links.
1313+ * @param pinfo A pointer to a receive file information, or \c null.
1314+ * @return If \a path refers to a symbolic link and \a follow_symlink is
1315+ * \c true, the type returned is of that to which the link refers; if \a path
1316+ * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
1317+ * \a path does not refer to a symbolic link, returns the type of \a path.
1318+ * @throws fs::exception for typical failures (file not found, invalid path,
1319+ * permission denied, etc).
1320+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
1321+ * unrecoverable failures.
1322+ */
1323+ZORBA_DLL_PUBLIC
1324+type get_type( char const *path, bool follow_symlink, info *pinfo = nullptr );
1325+
1326+/**
1327+ * Gets the type of the given file.
1328+ *
1329+ * @param path The full path to check.
1330+ * @param pinfo A pointer to a receive file information, or \c null.
1331+ * @return If \a path refers to a symbolic link, the type returned is of that
1332+ * to which the link refers; if \a path does not refer to a symbolic link,
1333+ * returns the type of \a path.
1334+ * @throws fs::exception for typical failures (file not found, invalid path,
1335+ * permission denied, etc).
1336+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
1337+ * unrecoverable failures.
1338+ */
1339+inline type get_type( char const *path, info *pinfo = nullptr ) {
1340+ return get_type( path, true, pinfo );
1341+}
1342+
1343+/**
1344+ * Gets the type of the given file.
1345+ *
1346+ * @tparam PathStringType The \a path string type.
1347+ * @param path The full path to check.
1348+ * @param follow_symlink If \c true, follows symbolic links.
1349+ * @param pinfo A pointer to a receive file information, or \c null.
1350+ * @return If \a path refers to a symbolic link and \a follow_symlink is
1351+ * \c true, the type returned is of that to which the link refers; if \a path
1352+ * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
1353+ * \a path does not refer to a symbolic link, returns the type of \a path.
1354+ * @throws fs::exception for typical failures (file not found, invalid path,
1355+ * permission denied, etc).
1356+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
1357+ * unrecoverable failures.
1358+ */
1359+template<class PathStringType> inline
1360+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),type>::type
1361+get_type( PathStringType const &path, bool follow_symlink,
1362+ info *pinfo = nullptr ) {
1363+ return get_type( path.c_str(), follow_symlink, pinfo );
1364+}
1365+
1366+/**
1367+ * Gets the type of the given file.
1368+ *
1369+ * @tparam PathStringType The \a path string type.
1370+ * @param path The full path to check.
1371+ * @param pinfo A pointer to a receive file information, or \c null.
1372+ * @return If \a path refers to a symbolic link, the type returned is of that
1373+ * to which the link refers; if \a path does not refer to a symbolic link,
1374+ * returns the type of \a path.
1375+ * @throws fs::exception for typical failures (file not found, invalid path,
1376+ * permission denied, etc).
1377+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
1378+ * unrecoverable failures.
1379+ */
1380+template<class PathStringType> inline
1381+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),type>::type
1382+get_type( PathStringType const &path, info *pinfo = nullptr ) {
1383+ return get_type( path.c_str(), pinfo );
1384+}
1385+
1386+#endif /* ZORBA_WITH_FILE_ACCESS */
1387+
1388+////////// Directory iteration ////////////////////////////////////////////////
1389+
1390+#ifdef ZORBA_WITH_FILE_ACCESS
1391+
1392+/**
1393+ * An %fs::iterator iterates over the entries in a directory.
1394+ */
1395+class ZORBA_DLL_PUBLIC iterator {
1396+public:
1397+ /**
1398+ * Information for a directory entry.
1399+ */
1400+ struct entry {
1401+ char const *name;
1402+ fs::type type;
1403+ };
1404+
1405+ /**
1406+ * Constructs an %iterator.
1407+ *
1408+ * @param path The full path to the directory to iterate over.
1409+ * @throws fs::exception if the construction failed, e.g., path not found.
1410+ */
1411+ iterator( char const *path ) : dir_path_( path ) {
1412+ ctor_impl();
1413+ }
1414+
1415+ /**
1416+ * Constructs an %iterator.
1417+ *
1418+ * @tparam PathStringType The \a path string type.
1419+ * @param path The full path to the directory to iterate over.
1420+ * @throws fs::exception if the construction failed, e.g., path not found.
1421+ */
1422+ template<class PathStringType>
1423+ iterator( PathStringType const &path,
1424+ typename std::enable_if<ZORBA_HAS_C_STR(PathStringType)
1425+ >::type* = 0 ) : dir_path_( path.c_str() ) {
1426+ ctor_impl();
1427+ }
1428+
1429+ /**
1430+ * Destroys this %iterator.
1431+ */
1432+ ~iterator();
1433+
1434+ /**
1435+ * Attempts to get the next directory entry.
1436+ *
1437+ * @return Returns \c true only if there is a next directory.
1438+ */
1439+ bool next();
1440+
1441+ /**
1442+ * Gets the current directory entry. The entry is undefined unless next()
1443+ * returned \c true.
1444+ *
1445+ * @return Returns said entry.
1446+ */
1447+ entry const& operator*() const {
1448+ return entry_;
1449+ }
1450+
1451+ /**
1452+ * Gets the current directory entry. The entry is undefined unless next()
1453+ * returned \c true.
1454+ *
1455+ * @return Returns said entry.
1456+ */
1457+ entry const* operator->() const {
1458+ return &entry_;
1459+ }
1460+
1461+ /**
1462+ * Gets the directory's path.
1463+ *
1464+ * @return Returns said path.
1465+ */
1466+ char const* path() const {
1467+ return dir_path_.c_str();
1468+ }
1469+
1470+ /**
1471+ * Resets this iterator to the beginning.
1472+ */
1473+ void reset();
1474+
1475+private:
1476+ std::string dir_path_;
1477+ entry entry_;
1478+#ifndef WIN32
1479+ DIR *dir_;
1480+#else
1481+ HANDLE dir_;
1482+ bool dir_is_empty_;
1483+ WIN32_FIND_DATA ent_data_;
1484+ char entry_name_buf_[ MAX_PATH ];
1485+ bool use_first_;
1486+
1487+ void win32_opendir( char const *path );
1488+ void win32_closedir();
1489+#endif /* WIN32 */
1490+
1491+ void ctor_impl();
1492+
1493+ // forbid
1494+ iterator( iterator const& );
1495+ iterator& operator=( iterator const& );
1496+};
1497+
1498+#endif /* ZORBA_WITH_FILE_ACCESS */
1499+
1500+////////// Path normalization /////////////////////////////////////////////////
1501+
1502+/**
1503+ * Gets the normalized path of the given path. A normalized path is one that:
1504+ * - has \c file:// URIs converted to paths
1505+ * - has directory separators corrected for the host operating system
1506+ * - has adjacent directory separators combined, e.g., \c /a//b becomes \c /a/b
1507+ * - has \c ./ removed, e.g., \c /a/./b becomes \c /a/b
1508+ * - has \c ../ removed, e.g., \c /a/b/../c becomes \c /a/c
1509+ *
1510+ * @param path The path to normalize.
1511+ * @param base The base path. If not empty, is prepended to \a path.
1512+ * @return Returns the normalized path.
1513+ * @throws std::invalid_argument for malformed paths.
1514+ */
1515+ZORBA_DLL_PUBLIC
1516+std::string normalize_path( char const *path, char const *base = nullptr );
1517+
1518+/**
1519+ * Gets the normalized path of the given path. A normalized path is one that:
1520+ * - has \c file:// URIs converted to paths
1521+ * - has directory separators corrected for the host operating system
1522+ * - has adjacent directory separators combined, e.g., \c /a//b becomes \c /a/b
1523+ * - has \c ./ removed, e.g., \c /a/./b becomes \c /a/b
1524+ * - has \c ../ removed, e.g., \c /a/b/../c becomes \c /a/c
1525+ *
1526+ * @tparam PathStringType The \a path string type.
1527+ * @param path The path to normalize.
1528+ * @return Returns the normalized path.
1529+ * @throws std::invalid_argument for malformed paths.
1530+ */
1531+template<class PathStringType> inline
1532+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),std::string>::type
1533+normalize_path( PathStringType const &path ) {
1534+ return normalize_path( path.c_str() );
1535+}
1536+
1537+/**
1538+ * Gets the normalized path of the given path. A normalized path is one that:
1539+ * - has \c file:// URIs converted to paths
1540+ * - has directory separators corrected for the host operating system
1541+ * - has adjacent directory separators combined, e.g., \c /a//b becomes \c /a/b
1542+ * - has \c ./ removed, e.g., \c /a/./b becomes \c /a/b
1543+ * - has \c ../ removed, e.g., \c /a/b/../c becomes \c /a/c
1544+ *
1545+ * @tparam PathStringType The \a path string type.
1546+ * @tparam BaseStringType The \a base string type.
1547+ * @param path The path to normalize.
1548+ * @param base The base path. If not empty, is prepended to \a path.
1549+ * @return Returns the normalized path.
1550+ * @throws std::invalid_argument for malformed paths.
1551+ */
1552+template<class PathStringType,class BaseStringType> inline
1553+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType)
1554+ && ZORBA_HAS_C_STR(BaseStringType),
1555+ std::string>::type
1556+normalize_path( PathStringType const &path, BaseStringType const &base ) {
1557+ return normalize_path( path.c_str(), base.c_str() );
1558+}
1559+
1560+////////// Path manipulation //////////////////////////////////////////////////
1561+
1562+/**
1563+ * Appends a path component onto another path ensuring that exactly one
1564+ * separator is used.
1565+ *
1566+ * @tparam PathStringType1 The \a path1 string type.
1567+ * @param path1 The path to append to.
1568+ * @param path2 The path to append.
1569+ */
1570+template<class PathStringType1> inline
1571+typename std::enable_if<ZORBA_IS_STRING(PathStringType1),void>::type
1572+append( PathStringType1 &path1, char const *path2 ) {
1573+ if ( !path1.empty() && path1[ path1.size() - 1 ] != dir_separator
1574+ && path2[0] != dir_separator ) {
1575+ path1 += dir_separator;
1576+ }
1577+ path1 += path2;
1578+}
1579+
1580+/**
1581+ * Appends a path component onto another path.
1582+ *
1583+ * @tparam PathStringType1 The \a path1 string type.
1584+ * @tparam PathStringType2 The \a path2 string type.
1585+ * @param path1 The path to append to.
1586+ * @param path2 The path to append.
1587+ */
1588+template<class PathStringType1,class PathStringType2> inline
1589+typename std::enable_if<ZORBA_IS_STRING(PathStringType1)
1590+ && ZORBA_HAS_C_STR(PathStringType2),
1591+ void>::type
1592+append( PathStringType1 &path1, PathStringType2 const &path2 ) {
1593+ append( path1, path2.c_str() );
1594+}
1595+
1596+/**
1597+ * Makes a relative path into an absolute path.
1598+ *
1599+ * @param path The path to make absolute. It is assumes that the buffer to
1600+ * which \a path points is at least MAX_PATH bytes.
1601+ */
1602+ZORBA_DLL_PUBLIC
1603+void make_absolute( char *path );
1604+
1605+/**
1606+ * Makes a relative path into an absolute path.
1607+ *
1608+ * @tparam PathStringType The \a path string type.
1609+ * @param path The path to make absolute.
1610+ */
1611+template<class PathStringType> inline
1612+typename std::enable_if<ZORBA_IS_STRING(PathStringType),void>::type
1613+make_absolute( PathStringType &path ) {
1614+ if ( !is_absolute( path ) ) {
1615+#ifndef WIN32
1616+ typedef typename PathStringType::size_type size_type;
1617+ path.insert( static_cast<size_type>(0), 1, '/' );
1618+ path.insert( 0, curdir().c_str() );
1619+#else
1620+ char temp[ MAX_PATH ];
1621+ win32::make_absolute_impl( path.c_str(), temp );
1622+ path = temp;
1623+#endif /* WIN32 */
1624+ }
1625+}
1626+
1627+///////////////////////////////////////////////////////////////////////////////
1628+
1629+} // namespace fs
1630+} // namespace zorba
1631+#endif /* ZORBA_API_FS_UTIL_H */
1632+/*
1633+* Local variables:
1634+* mode: c++
1635+* End:
1636+*/
1637+/* vim:set et sw=2 ts=2: */
1638
1639=== removed file 'include/zorba/util/path.h'
1640--- include/zorba/util/path.h 2013-02-07 17:24:36 +0000
1641+++ include/zorba/util/path.h 1970-01-01 00:00:00 +0000
1642@@ -1,105 +0,0 @@
1643-/*
1644- * Copyright 2006-2008 The FLWOR Foundation.
1645- *
1646- * Licensed under the Apache License, Version 2.0 (the "License");
1647- * you may not use this file except in compliance with the License.
1648- * You may obtain a copy of the License at
1649- *
1650- * http://www.apache.org/licenses/LICENSE-2.0
1651- *
1652- * Unless required by applicable law or agreed to in writing, software
1653- * distributed under the License is distributed on an "AS IS" BASIS,
1654- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1655- * See the License for the specific language governing permissions and
1656- * limitations under the License.
1657- */
1658-
1659-#ifndef ZORBA_PATH_H
1660-#define ZORBA_PATH_H
1661-
1662-#include <string>
1663-#include <iostream>
1664-#include <zorba/config.h>
1665-
1666-namespace zorba {
1667-
1668-class ZORBA_DLL_PUBLIC filesystem_path {
1669-private:
1670- std::string path;
1671-
1672- void canonicalize ();
1673-
1674-protected:
1675- std::string
1676- getPathString() const;
1677-
1678-public:
1679- enum flags_t {
1680- CONVERT_SLASHES = 1,
1681- RESOLVE = 2
1682- };
1683-
1684-public:
1685-
1686- /**
1687- * @brief Utility function to normalize a path as a system conforming
1688- * path and optionally resolve it.
1689- *
1690- * This function takes a path (as system path, file uri) and normalizes it.
1691- * It converts file URIs to system paths and replaces '/' and '\' to the
1692- * platform specific directory separator ('\' on Windows, '/' on UNIX like
1693- * operating systems like Linux and Mac OS X).
1694- * If the parameter base is set, it also resolves the path.
1695- *
1696- * @param in The path to normalize.
1697- * @param base The base name to resolve a path (default = ""), if this is the
1698- * empty string, it does not resolve anything, but only normalizes
1699- * the path.
1700- * @return Returns a normalized and optionally a resolved path.
1701- */
1702- static std::string normalize_path(std::string const &in, std::string const &base = "");
1703-
1704- // from current dir
1705- filesystem_path ();
1706-
1707- filesystem_path (const std::string &path_, int flags = 0);
1708-
1709- filesystem_path (const filesystem_path &base, const filesystem_path &rel) {
1710- if (rel.is_complete ())
1711- *this = rel;
1712- else {
1713- *this = base.get_path () + get_directory_separator () + rel.get_path ();
1714- canonicalize ();
1715- }
1716- }
1717-
1718- filesystem_path &operator = (const std::string &p_)
1719- { path = p_; canonicalize (); return *this; }
1720-
1721- const std::string &get_path () const { return path; }
1722- const char *c_str () const { return path.c_str (); }
1723- operator const std::string & () const { return path; }
1724-
1725- bool is_complete () const;
1726- bool is_root () const;
1727- void resolve_relative ();
1728-
1729- filesystem_path branch_path () const;
1730-
1731- static const char *get_directory_separator ();
1732- static const char *get_path_separator ();
1733-};
1734-
1735-inline std::ostream &operator<< (std::ostream &os, const filesystem_path &p) {
1736- return os << p.get_path ();
1737-}
1738-
1739-
1740-} // namespace zorba
1741-#endif /* ZORBA_PATH_H */
1742-/*
1743-* Local variables:
1744-* mode: c++
1745-* End:
1746-*/
1747-/* vim:set et sw=2 ts=2: */
1748
1749=== added file 'include/zorba/util/stream_util.h'
1750--- include/zorba/util/stream_util.h 1970-01-01 00:00:00 +0000
1751+++ include/zorba/util/stream_util.h 2013-06-11 16:49:27 +0000
1752@@ -0,0 +1,48 @@
1753+/*
1754+ * Copyright 2006-2008 The FLWOR Foundation.
1755+ *
1756+ * Licensed under the Apache License, Version 2.0 (the "License");
1757+ * you may not use this file except in compliance with the License.
1758+ * You may obtain a copy of the License at
1759+ *
1760+ * http://www.apache.org/licenses/LICENSE-2.0
1761+ *
1762+ * Unless required by applicable law or agreed to in writing, software
1763+ * distributed under the License is distributed on an "AS IS" BASIS,
1764+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1765+ * See the License for the specific language governing permissions and
1766+ * limitations under the License.
1767+ */
1768+
1769+#pragma once
1770+#ifndef ZORBA_API_STREAM_UTIL_H
1771+#define ZORBA_API_STREAM_UTIL_H
1772+
1773+#include <iostream>
1774+
1775+#include <zorba/config.h>
1776+
1777+namespace zorba {
1778+
1779+///////////////////////////////////////////////////////////////////////////////
1780+
1781+/**
1782+ * Skips the UTF-8 byte order mark (BOM), if any.
1783+ *
1784+ * @param is The istream to read.
1785+ * @return Returns \c true only if a BOM was present and skipped.
1786+ */
1787+ZORBA_DLL_PUBLIC
1788+bool skip_utf8_bom( std::istream &is );
1789+
1790+///////////////////////////////////////////////////////////////////////////////
1791+
1792+} // namespace zorba
1793+
1794+#endif /* ZORBA_API_STREAM_UTIL_H */
1795+/*
1796+ * Local variables:
1797+ * mode: c++
1798+ * End:
1799+ */
1800+/* vim:set et sw=2 ts=2: */
1801
1802=== modified file 'modules/ExternalModules.conf'
1803--- modules/ExternalModules.conf 2013-05-29 00:52:05 +0000
1804+++ modules/ExternalModules.conf 2013-06-11 16:49:27 +0000
1805@@ -27,9 +27,10 @@
1806 # currently only works for bzr, since svn tags are just different URLS)
1807
1808 archive bzr lp:zorba/archive-module zorba-2.9
1809-csv bzr lp:zorba/csv-module zorba-2.9
1810-data-cleaning bzr lp:zorba/data-cleaning-module zorba-2.9
1811-data-formatting bzr lp:zorba/data-formatting-module zorba-2.9.1
1812+#csv bzr lp:zorba/csv-module
1813+csv bzr lp:~zorba-coders/zorba/bug-1180220-util-jvm
1814+data-cleaning bzr lp:zorba/data-cleaning-module
1815+data-formatting bzr lp:zorba/data-formatting-module
1816 excel bzr lp:zorba/excel-module zorba-2.9
1817 info-extraction bzr lp:zorba/info-extraction-module zorba-2.9
1818 geo bzr lp:zorba/geo-module zorba-2.9
1819@@ -38,17 +39,17 @@
1820 html bzr lp:zorba/html-module zorba-2.9
1821 http-client bzr lp:zorba/http-client-module zorba-2.9
1822 image bzr lp:zorba/image-module zorba-2.9
1823-jdbc bzr lp:zorba/jdbc-module zorba-2.9
1824+jdbc bzr lp:zorba/jdbc-module
1825 languages bzr lp:zorba/languages-module zorba-2.9
1826-oracle-nosql-db bzr lp:zorba/oracle-nosql-db-module zorba-2.9
1827+oracle-nosql-db bzr lp:zorba/oracle-nosql-db-module
1828 oauth bzr lp:zorba/oauth-module zorba-2.9
1829-process bzr lp:zorba/process-module zorba-2.9
1830-read-pdf bzr lp:zorba/read-pdf-module zorba-2.9.1
1831+process bzr lp:zorba/process-module
1832+read-pdf bzr lp:zorba/read-pdf-module
1833 security bzr lp:zorba/security-module zorba-2.9
1834 system bzr lp:zorba/system-module zorba-2.9
1835 email bzr lp:zorba/email-module zorba-2.9
1836-util-jvm bzr lp:zorba/util-jvm-module zorba-2.9.1
1837-schema-tools bzr lp:zorba/schema-tools-module zorba-2.9.1
1838+util-jvm bzr lp:zorba/util-jvm-module
1839+schema-tools bzr lp:zorba/schema-tools-module
1840 stack bzr lp:zorba/stack-module zorba-2.9
1841 queue bzr lp:zorba/queue-module zorba-2.9
1842 couchbase bzr lp:zorba/couchbase-module zorba-2.9
1843
1844=== modified file 'modules/org/expath/ns/file.xq.src/file.cpp'
1845--- modules/org/expath/ns/file.xq.src/file.cpp 2013-04-19 22:25:21 +0000
1846+++ modules/org/expath/ns/file.xq.src/file.cpp 2013-06-11 16:49:27 +0000
1847@@ -16,25 +16,28 @@
1848
1849 #include "file.h"
1850
1851+// standard
1852 #include <fstream>
1853 #include <memory>
1854 #include <sstream>
1855 #include <stdexcept>
1856
1857+// Zorba
1858 #include <zorba/base64.h>
1859+#include <zorba/diagnostic_list.h>
1860 #include <zorba/empty_sequence.h>
1861-#include <zorba/diagnostic_list.h>
1862-#include <zorba/file.h>
1863 #include <zorba/serializer.h>
1864 #include <zorba/singleton_item_sequence.h>
1865-#include <zorba/util/path.h>
1866+#include <zorba/transcode_stream.h>
1867 #include <zorba/user_exception.h>
1868-#include <zorba/transcode_stream.h>
1869+#include <zorba/util/fs_util.h>
1870+#include <zorba/util/stream_util.h>
1871
1872+// local
1873 #include "file_module.h"
1874
1875-
1876-namespace zorba { namespace filemodule {
1877+namespace zorba {
1878+namespace filemodule {
1879
1880 //*****************************************************************************
1881
1882@@ -45,129 +48,87 @@
1883
1884 ItemSequence_t
1885 CreateDirectoryFunction::evaluate(
1886- const ExternalFunction::Arguments_t& aArgs,
1887- const StaticContext* aSctxCtx,
1888- const DynamicContext* aDynCtx) const
1889+ ExternalFunction::Arguments_t const &aArgs,
1890+ StaticContext const*,
1891+ DynamicContext const* ) const
1892 {
1893- String lFileStr = getFilePathString(aArgs, 0);
1894- File_t lFile = File::createFile(lFileStr.c_str());
1895-
1896- // precondition
1897- if (lFile->isFile()) {
1898- raiseFileError("FOFL0002", "A file already exists at this path", lFile->getFilePath());
1899- }
1900-
1901- // actual mkdir
1902+ String const path( getFilePathString( aArgs, 0 ) );
1903+
1904+ if ( fs::get_type( path ) )
1905+ raiseFileError( "FOFL0002", "file already exists", path );
1906+
1907 try {
1908- lFile->mkdir(true);
1909- } catch (ZorbaException const& ze) {
1910- std::stringstream lSs;
1911- lSs << "An unknown error occured: " << ze.what() << "Can not create directory";
1912- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
1913- } catch (...) {
1914- //assert(false); if this happens errors are not proprly thrown
1915- raiseFileError("FOFL9999", "Can not create directory", lFile->getFilePath());
1916- }
1917-
1918- // postcondition
1919- if (!(lFile->isDirectory())) {
1920- raiseFileError("FOFL9999", "Can not create directory", lFile->getFilePath());
1921- }
1922-
1923- return ItemSequence_t(new EmptySequence());
1924+ fs::mkdir( path );
1925+ }
1926+ catch ( std::exception const &e ) {
1927+ throw raiseFileError( "FOFL9999", e.what(), path );
1928+ }
1929+
1930+ return ItemSequence_t( new EmptySequence() );
1931 }
1932
1933 //*****************************************************************************
1934
1935-DeleteFileImplFunction::DeleteFileImplFunction(const FileModule* aModule)
1936- : FileFunction(aModule)
1937+DeleteFileImplFunction::DeleteFileImplFunction(const FileModule* aModule) :
1938+ FileFunction(aModule)
1939 {
1940 }
1941
1942 ItemSequence_t
1943 DeleteFileImplFunction::evaluate(
1944- const ExternalFunction::Arguments_t& aArgs,
1945- const StaticContext* aSctxCtx,
1946- const DynamicContext* aDynCtx) const
1947+ ExternalFunction::Arguments_t const &aArgs,
1948+ StaticContext const*,
1949+ DynamicContext const* ) const
1950 {
1951- String lFileStr = getFilePathString(aArgs, 0);
1952- File_t lFile = File::createFile(lFileStr.c_str());
1953-
1954- // precondition
1955- if (!lFile->exists( false )) {
1956- raiseFileError("FOFL0001", "A file or directory does not exist at this path", lFile->getFilePath());
1957- }
1958-
1959- // actual remove
1960+ String const path( getFilePathString( aArgs, 0 ) );
1961+
1962+ if ( !fs::get_type( path, false ) )
1963+ raiseFileError( "FOFL0001", "file not found", path );
1964+
1965 try {
1966- lFile->remove();
1967- } catch (ZorbaException const& ze) {
1968- std::stringstream lSs;
1969- lSs << "An unknown error occured: " << ze.what() << "Can not delete file";
1970- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
1971- } catch (...) {
1972- //assert(false); if this happens errors are not proprly thrown
1973- raiseFileError("FOFL9999", "Can not delete directory", lFile->getFilePath());
1974- }
1975-
1976- // postcondition
1977- if (lFile->exists( false )) {
1978- raiseFileError("FOFL9999", "The file at this path could not be deleted", lFile->getFilePath());
1979- }
1980-
1981- return ItemSequence_t(new EmptySequence());
1982+ fs::remove( path );
1983+ }
1984+ catch ( std::exception const &e ) {
1985+ throw raiseFileError( "FOFL9999", e.what(), path );
1986+ }
1987+
1988+ return ItemSequence_t( new EmptySequence() );
1989 }
1990
1991 //*****************************************************************************
1992
1993-ReadBinaryFunction::ReadBinaryFunction(const FileModule* aModule)
1994- : FileFunction(aModule)
1995+ReadBinaryFunction::ReadBinaryFunction( FileModule const *aModule ) :
1996+ FileFunction( aModule )
1997 {
1998 }
1999
2000 ItemSequence_t
2001 ReadBinaryFunction::evaluate(
2002- const ExternalFunction::Arguments_t& aArgs,
2003- const StaticContext* aSctxCtx,
2004- const DynamicContext* aDynCtx) const
2005+ ExternalFunction::Arguments_t const &aArgs,
2006+ StaticContext const*,
2007+ DynamicContext const* ) const
2008 {
2009- String lFileStr = getFilePathString(aArgs, 0);
2010- File_t lFile = File::createFile(lFileStr.c_str());
2011-
2012- // preconditions
2013- if (!lFile->exists()) {
2014- raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());
2015- }
2016- if (lFile->isDirectory()) {
2017- raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
2018- }
2019-
2020- // actual read
2021- Item lItem;
2022+ String const path( getFilePathString( aArgs, 0 ) );
2023+
2024+ fs::type const fs_type = fs::get_type( path );
2025+ if ( !fs_type )
2026+ raiseFileError( "FOFL0001", "file not found", path );
2027+ if ( fs_type != fs::file )
2028+ raiseFileError( "FOFL0004", "not a plain file", path );
2029+
2030 try {
2031- std::unique_ptr<std::ifstream> lInStream;
2032- lInStream.reset( new std::ifstream() );
2033- lFile->openInputStream(*lInStream.get(), true, false);
2034-
2035- lItem = theModule->getItemFactory()->createStreamableBase64Binary(
2036- *lInStream.release(), &FileModule::streamReleaser, true
2037- );
2038-
2039- } catch (ZorbaException const& ze) {
2040- std::stringstream lSs;
2041- lSs << "An unknown error occured: " << ze.what() << "Can not read file";
2042- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
2043- } catch (...) {
2044- //assert(false); if this happens errors are not proprly thrown
2045- raiseFileError("FOFL9999", "Can not read file", lFile->getFilePath());
2046- }
2047-
2048- if (lItem.isNull()) {
2049- Item lQName = theModule->getItemFactory()->createQName("http://www.w3.org/2005/xqt-errors", "err", "XPTY0004");
2050- throw USER_EXCEPTION(lQName, "Error while building the base64binary item." );
2051- }
2052-
2053- return ItemSequence_t(new SingletonItemSequence(lItem));
2054+ std::unique_ptr<std::ifstream> pin(
2055+ new std::ifstream( path.c_str(), std::ios_base::binary )
2056+ );
2057+ Item item = theModule->getItemFactory()->createStreamableBase64Binary(
2058+ *pin, &FileModule::streamReleaser, true
2059+ );
2060+ pin.release();
2061+ return ItemSequence_t( new SingletonItemSequence( item ) );
2062+ }
2063+ catch ( std::exception const &e ) {
2064+ throw raiseFileError( "FOFL9999", e.what(), path );
2065+ }
2066 }
2067
2068 //*****************************************************************************
2069@@ -179,47 +140,43 @@
2070
2071 ItemSequence_t
2072 ReadTextFunction::evaluate(
2073- const ExternalFunction::Arguments_t& aArgs,
2074- const StaticContext* aSctxCtx,
2075- const DynamicContext* aDynCtx) const
2076+ ExternalFunction::Arguments_t const &aArgs,
2077+ StaticContext const*,
2078+ DynamicContext const* ) const
2079 {
2080- String lFileStr = getFilePathString(aArgs, 0);
2081- File_t lFile = File::createFile(lFileStr.c_str());
2082- String lEncoding("UTF-8");
2083-
2084- // preconditions
2085- if (!lFile->exists()) {
2086- raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());
2087- }
2088- if (lFile->isDirectory()) {
2089- raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
2090- }
2091-
2092- if (aArgs.size() == 2) {
2093- lEncoding = getEncodingArg(aArgs, 1);
2094- }
2095+ String const path( getFilePathString( aArgs, 0 ) );
2096+ String lEncoding( "UTF-8" );
2097+
2098+ fs::type const fs_type = fs::get_type( path );
2099+ if ( !fs_type )
2100+ raiseFileError( "FOFL0001", "file not found", path );
2101+ if ( fs_type != fs::file )
2102+ raiseFileError( "FOFL0004", "not a plain file", path );
2103+
2104+ if ( aArgs.size() == 2 )
2105+ lEncoding = getEncodingArg( aArgs, 1 );
2106
2107 zorba::Item lResult;
2108- std::unique_ptr<std::ifstream> lInStream;
2109- if ( transcode::is_necessary( lEncoding.c_str() ) )
2110- {
2111+
2112+ std::unique_ptr<std::ifstream> pin;
2113+ if ( transcode::is_necessary( lEncoding.c_str() ) ) {
2114 try {
2115- lInStream.reset( new transcode::stream<std::ifstream>(lEncoding.c_str()) );
2116- } catch (std::invalid_argument const&)
2117- {
2118- raiseFileError("FOFL0006", "Unsupported encoding", lEncoding.c_str());
2119- }
2120- }
2121- else
2122- {
2123- lInStream.reset( new std::ifstream() );
2124- }
2125- lFile->openInputStream(*lInStream.get(), false, true);
2126+ pin.reset( new transcode::stream<std::ifstream>( lEncoding.c_str() ) );
2127+ }
2128+ catch ( std::exception const &e ) {
2129+ throw raiseFileError("FOFL0006", e.what(), lEncoding.c_str() );
2130+ }
2131+ } else
2132+ pin.reset( new std::ifstream() );
2133+
2134+ pin->open( path.c_str() );
2135+ skip_utf8_bom( *pin );
2136 lResult = theModule->getItemFactory()->createStreamableString(
2137- *lInStream.release(), &FileModule::streamReleaser, lFileStr.c_str(), true
2138- );
2139- return ItemSequence_t(new SingletonItemSequence(lResult));
2140+ *pin, &FileModule::streamReleaser, path.c_str(), true
2141+ );
2142+ pin.release();
2143
2144+ return ItemSequence_t( new SingletonItemSequence( lResult ) );
2145 }
2146
2147 //*****************************************************************************
2148@@ -231,34 +188,30 @@
2149
2150 ItemSequence_t
2151 ReadTextLinesFunction::evaluate(
2152- const ExternalFunction::Arguments_t& aArgs,
2153- const StaticContext* aSctxCtx,
2154- const DynamicContext* aDynCtx) const
2155+ ExternalFunction::Arguments_t const &aArgs,
2156+ StaticContext const*,
2157+ DynamicContext const* ) const
2158 {
2159- String lFileStr = getFilePathString(aArgs, 0);
2160- File_t lFile = File::createFile(lFileStr.c_str());
2161- String lEncoding("UTF-8");
2162-
2163- // preconditions
2164- if (!lFile->exists()) {
2165- raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());
2166- }
2167- if (lFile->isDirectory()) {
2168- raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
2169- }
2170-
2171- lEncoding = getEncodingArg(aArgs, 1);
2172-
2173- return ItemSequence_t(new LinesItemSequence(lFile, lEncoding, this));
2174+ String const path( getFilePathString( aArgs, 0 ) );
2175+ String const lEncoding( getEncodingArg( aArgs, 1 ) );
2176+
2177+ fs::type const fs_type = fs::get_type( path );
2178+ if ( !fs_type )
2179+ raiseFileError( "FOFL0001", "file not found", path );
2180+ if ( fs_type != fs::file )
2181+ raiseFileError( "FOFL0004", "not a plain file", path );
2182+
2183+ return ItemSequence_t( new LinesItemSequence( path, lEncoding, this ) );
2184 }
2185
2186 ReadTextLinesFunction::LinesItemSequence::LinesItemSequence(
2187- const File_t& aFile,
2188- const String& aEncoding,
2189- const ReadTextLinesFunction* aFunc)
2190- : theFile(aFile),
2191- theEncoding(aEncoding),
2192- theFunc(aFunc)
2193+ String const &aFile,
2194+ String const &aEncoding,
2195+ ReadTextLinesFunction const *aFunc
2196+) :
2197+ theFile( aFile ),
2198+ theEncoding( aEncoding ),
2199+ theFunc( aFunc )
2200 {
2201 }
2202
2203@@ -266,18 +219,19 @@
2204 ReadTextLinesFunction::LinesItemSequence::getIterator()
2205 {
2206 return new ReadTextLinesFunction::LinesItemSequence::LinesIterator(
2207- theFile, theEncoding, theFunc
2208- );
2209+ theFile, theEncoding, theFunc
2210+ );
2211 }
2212
2213 ReadTextLinesFunction::LinesItemSequence::LinesIterator::LinesIterator(
2214- const File_t& aFile,
2215- const String& aEncoding,
2216- const ReadTextLinesFunction* aFunc)
2217- : theFile(aFile),
2218- theEncoding(aEncoding),
2219- theFunc(aFunc),
2220- theStream(0)
2221+ String const &aFile,
2222+ String const &aEncoding,
2223+ ReadTextLinesFunction const *aFunc
2224+) :
2225+ theFile(aFile),
2226+ theEncoding(aEncoding),
2227+ theFunc(aFunc),
2228+ theStream(0)
2229 {
2230 }
2231
2232@@ -289,42 +243,32 @@
2233 void
2234 ReadTextLinesFunction::LinesItemSequence::LinesIterator::open()
2235 {
2236- if ( transcode::is_necessary( theEncoding.c_str() ) )
2237- {
2238- try
2239- {
2240- theStream = new transcode::stream<std::ifstream>(theEncoding.c_str());
2241- }
2242- catch (std::invalid_argument const& e)
2243- {
2244- theFunc->raiseFileError("FOFL0006", "Unsupported encoding", theEncoding.c_str());
2245- }
2246- }
2247- else
2248- {
2249+ if ( transcode::is_necessary( theEncoding.c_str() ) ) {
2250+ try {
2251+ theStream = new transcode::stream<std::ifstream>( theEncoding.c_str() );
2252+ }
2253+ catch ( std::invalid_argument const &e ) {
2254+ theFunc->raiseFileError( "FOFL0006", e.what(), theEncoding.c_str() );
2255+ }
2256+ } else
2257 theStream = new std::ifstream();
2258- }
2259- theFile->openInputStream(*theStream, false, true);
2260+
2261+ theStream->open( theFile.c_str() );
2262 }
2263
2264 bool
2265 ReadTextLinesFunction::LinesItemSequence::LinesIterator::next(Item& aRes)
2266 {
2267- if (!theStream || !theStream->good())
2268+ if ( !theStream || !theStream->good() )
2269 return false;
2270
2271- std::string lStr;
2272- getline(*theStream, lStr);
2273+ std::string s;
2274+ getline( *theStream, s );
2275+ if ( theStream->bad() )
2276+ return false;
2277
2278- if (theStream->bad())
2279- {
2280- return false;
2281- }
2282- else
2283- {
2284- aRes = theFunc->theModule->getItemFactory()->createString(lStr);
2285- return true;
2286- }
2287+ aRes = theFunc->theModule->getItemFactory()->createString( s );
2288+ return true;
2289 }
2290
2291 void
2292@@ -342,220 +286,176 @@
2293
2294 //*****************************************************************************
2295
2296-ExistsFunction::ExistsFunction(const FileModule* aModule)
2297- : FileFunction(aModule)
2298+ExistsFunction::ExistsFunction(const FileModule* aModule) :
2299+ FileFunction( aModule )
2300 {
2301 }
2302
2303 ItemSequence_t
2304 ExistsFunction::evaluate(
2305- const ExternalFunction::Arguments_t& aArgs,
2306- const StaticContext* aSctxCtx,
2307- const DynamicContext* aDynCtx) const
2308+ ExternalFunction::Arguments_t const &aArgs,
2309+ StaticContext const*,
2310+ DynamicContext const* ) const
2311 {
2312- String const lFileStr = getFilePathString(aArgs, 0);
2313- bool const lFollowSymlinks = getItem(aArgs, 1).getBooleanValue();
2314-
2315- File_t lFile = File::createFile(lFileStr.c_str());
2316- bool const lFileExists = lFile->exists(lFollowSymlinks);
2317-
2318- return ItemSequence_t(new SingletonItemSequence(
2319- theModule->getItemFactory()->createBoolean(lFileExists)));
2320+ String const path = getFilePathString( aArgs, 0 );
2321+ bool const follow_symlink = getItem( aArgs, 1 ).getBooleanValue();
2322+ bool const exists = !!fs::get_type( path, follow_symlink );
2323+ return ItemSequence_t(
2324+ new SingletonItemSequence(
2325+ theModule->getItemFactory()->createBoolean( exists )
2326+ )
2327+ );
2328 }
2329
2330 //*****************************************************************************
2331
2332-IsDirectoryFunction::IsDirectoryFunction(const FileModule* aModule)
2333- : FileFunction(aModule)
2334+IsDirectoryFunction::IsDirectoryFunction( FileModule const *aModule ) :
2335+ FileFunction( aModule )
2336 {
2337 }
2338
2339 ItemSequence_t
2340 IsDirectoryFunction::evaluate(
2341- const ExternalFunction::Arguments_t& aArgs,
2342- const StaticContext* aSctxCtx,
2343- const DynamicContext* aDynCtx) const
2344+ ExternalFunction::Arguments_t const &aArgs,
2345+ StaticContext const*,
2346+ DynamicContext const* ) const
2347 {
2348- bool lResult = false;
2349- String lFileStr = getFilePathString(aArgs, 0);
2350-
2351- File_t lFile = File::createFile(lFileStr.c_str());
2352- if (lFile->isDirectory()) {
2353- lResult = true;
2354- }
2355- return ItemSequence_t(new SingletonItemSequence(
2356- theModule->getItemFactory()->createBoolean(lResult)));
2357+ String const path( getFilePathString( aArgs, 0 ) );
2358+ bool const is_directory = fs::get_type( path ) == fs::directory;
2359+ return ItemSequence_t(
2360+ new SingletonItemSequence(
2361+ theModule->getItemFactory()->createBoolean( is_directory )
2362+ )
2363+ );
2364 }
2365
2366 //*****************************************************************************
2367
2368-IsFileFunction::IsFileFunction(const FileModule* aModule)
2369- : FileFunction(aModule)
2370+IsFileFunction::IsFileFunction( FileModule const *aModule ) :
2371+ FileFunction( aModule )
2372 {
2373 }
2374
2375 ItemSequence_t
2376 IsFileFunction::evaluate(
2377- const ExternalFunction::Arguments_t& aArgs,
2378- const StaticContext* aSctxCtx,
2379- const DynamicContext* aDynCtx) const
2380+ ExternalFunction::Arguments_t const &aArgs,
2381+ StaticContext const*,
2382+ DynamicContext const* ) const
2383 {
2384- bool lResult = false;
2385- String lFileStr = getFilePathString(aArgs, 0);
2386-
2387- File_t lFile = File::createFile(lFileStr.c_str());
2388- if (lFile->isFile()) {
2389- lResult = true;
2390- }
2391- return ItemSequence_t(new SingletonItemSequence(
2392- theModule->getItemFactory()->createBoolean(lResult)));
2393+ String const path( getFilePathString( aArgs, 0 ) );
2394+ bool const is_file = fs::get_type( path ) == fs::file;
2395+ return ItemSequence_t(
2396+ new SingletonItemSequence(
2397+ theModule->getItemFactory()->createBoolean( is_file )
2398+ )
2399+ );
2400 }
2401
2402 //*****************************************************************************
2403
2404-IsSymlinkFunction::IsSymlinkFunction(const FileModule* aModule)
2405- : FileFunction(aModule)
2406+IsSymlinkFunction::IsSymlinkFunction( FileModule const *aModule ) :
2407+ FileFunction( aModule )
2408 {
2409 }
2410
2411 ItemSequence_t
2412 IsSymlinkFunction::evaluate(
2413- const ExternalFunction::Arguments_t& aArgs,
2414- const StaticContext* aSctxCtx,
2415- const DynamicContext* aDynCtx) const
2416+ ExternalFunction::Arguments_t const &aArgs,
2417+ StaticContext const*,
2418+ DynamicContext const* ) const
2419 {
2420- bool lResult = false;
2421- String lFileStr = getFilePathString(aArgs, 0);
2422-
2423- File_t lFile = File::createFile(lFileStr.c_str());
2424- if (lFile->isLink()) {
2425- lResult = true;
2426- }
2427- return ItemSequence_t(new SingletonItemSequence(
2428- theModule->getItemFactory()->createBoolean(lResult)));
2429+ String const path( getFilePathString( aArgs, 0 ) );
2430+ bool const is_symlink = fs::get_type( path, false ) == fs::link;
2431+ return ItemSequence_t(
2432+ new SingletonItemSequence(
2433+ theModule->getItemFactory()->createBoolean( is_symlink )
2434+ )
2435+ );
2436 }
2437
2438 //*****************************************************************************
2439
2440-CopyFileImplFunction::CopyFileImplFunction(const FileModule* aModule)
2441- : FileFunction(aModule)
2442+CopyFileImplFunction::CopyFileImplFunction( FileModule const *aModule ) :
2443+ FileFunction( aModule )
2444 {
2445 }
2446
2447 ItemSequence_t
2448 CopyFileImplFunction::evaluate(
2449- const ExternalFunction::Arguments_t& aArgs,
2450- const StaticContext* aSctxCtx,
2451- const DynamicContext* aDynCtx) const
2452+ ExternalFunction::Arguments_t const &aArgs,
2453+ StaticContext const*,
2454+ DynamicContext const* ) const
2455 {
2456- String lSrcFileStr = getFilePathString(aArgs, 0);
2457- File_t lSrcFile = File::createFile(lSrcFileStr.c_str());
2458- String lDstStr = getFilePathString(aArgs, 1);
2459- File_t lDst = File::createFile(lDstStr.c_str());
2460-
2461- // preconditions
2462- if (!lSrcFile->exists()) {
2463- raiseFileError("FOFL0001", "A file does not exist at this path", lSrcFile->getFilePath());
2464- }
2465- // is this a file? (the recursive version is implemented in XQuery)
2466- if (lSrcFile->isDirectory()) {
2467- raiseFileError("FOFL0004", "This operation is non-recursive. The source path points to a directory", lSrcFile->getFilePath());
2468- }
2469-
2470- // do we copy into a directory?
2471- if (lDst->isDirectory()) {
2472- lDstStr = lDst->getFilePath();
2473- String lSrcPath = lSrcFile->getFilePath();
2474- int lLastSep = lSrcPath.rfind(File::getDirectorySeparator());
2475- String lName = lSrcPath.substr(lLastSep);
2476- lDstStr = lDstStr.append(lName.c_str());
2477- lDst = File::createFile(lDstStr.c_str());
2478- }
2479-
2480- // is the destination still is a directory?
2481- if (lDst->isDirectory()) {
2482- raiseFileError("FOFL0002", "The destination path already exists", lSrcFile->getFilePath());
2483- }
2484-
2485- // do we copy a file to its own location?
2486- if (lSrcFile->getFilePath() == lDst->getFilePath()) {
2487- raiseFileError("FOFL9999", "The source and destination paths can not point to the same file", lSrcFile->getFilePath());
2488- }
2489-
2490- // actual copy
2491+ String const src_path( getFilePathString( aArgs, 0 ) );
2492+ String dst_path( getFilePathString( aArgs, 1 ) );
2493+
2494+ fs::type const src_type = fs::get_type( src_path );
2495+ if ( !src_type )
2496+ raiseFileError( "FOFL0001", "file not found", src_path );
2497+ if ( src_type != fs::file )
2498+ raiseFileError( "FOFL0004", "not a plain file", src_path );
2499+
2500+ fs::type dst_type = fs::get_type( dst_path );
2501+ if ( dst_type == fs::directory ) { // we are copying into a directory
2502+ fs::append( dst_path, fs::base_name( src_path ) );
2503+ dst_type = fs::get_type( dst_path );
2504+ if ( dst_type == fs::directory )
2505+ raiseFileError( "FOFL0002", "path already exists", dst_path );
2506+ }
2507+
2508+ if ( src_path == dst_path )
2509+ raiseFileError( "FOFL9999", "source and destination paths must not be equal", src_path );
2510+
2511 try {
2512-
2513- // open the output stream in the desired write mode
2514- std::ifstream lInStream;
2515- std::ofstream lOutStream;
2516- lSrcFile->openInputStream(lInStream, true, false);
2517- lDst->openOutputStream(lOutStream, true, false);
2518-
2519- // copy the data
2520- char lBuf[1024];
2521- while (!lInStream.eof()) {
2522- lInStream.read(lBuf, 1024);
2523- lOutStream.write(lBuf, lInStream.gcount());
2524+ std::ifstream fin( src_path.c_str(), std::ios_base::binary );
2525+ std::ofstream fout( dst_path.c_str(), std::ios_base::binary | std::ios_base::trunc );
2526+ char buf[ 8192 ];
2527+ while ( !fin.eof() ) {
2528+ fin.read( buf, sizeof buf );
2529+ fout.write( buf, fin.gcount() );
2530 }
2531-
2532- // close the streams
2533- lInStream.close();
2534- lOutStream.close();
2535-
2536- } catch (ZorbaException const& ze) {
2537- std::stringstream lSs;
2538- lSs << "An unknown error occured: " << ze.what() << "Can not copy file";
2539- raiseFileError("FOFL9999", lSs.str(), lSrcFile->getFilePath());
2540- } catch (...) {
2541- //assert(false); if this happens errors are not proprly thrown
2542- raiseFileError("FOFL9999", "Can not copy file", lSrcFile->getFilePath());
2543- }
2544-
2545- return ItemSequence_t(new EmptySequence());
2546+ }
2547+ catch ( std::exception const &e ) {
2548+ throw raiseFileError( "FOFL9999", e.what(), src_path );
2549+ }
2550+
2551+ return ItemSequence_t( new EmptySequence() );
2552 }
2553
2554 //*****************************************************************************
2555
2556-ListFunction::ListFunction(const FileModule* aModule)
2557- : FileFunction(aModule)
2558+ListFunction::ListFunction( FileModule const *aModule ) :
2559+ FileFunction( aModule )
2560 {
2561 }
2562
2563 ItemSequence_t
2564 ListFunction::evaluate(
2565- const ExternalFunction::Arguments_t& aArgs,
2566- const StaticContext* aSctxCtx,
2567- const DynamicContext* aDynCtx) const
2568+ ExternalFunction::Arguments_t const &aArgs,
2569+ StaticContext const*,
2570+ DynamicContext const* ) const
2571 {
2572- String lFileStr = getFilePathString(aArgs, 0);
2573- File_t lFile = File::createFile(lFileStr.c_str());
2574-
2575- // precondition
2576- if (!lFile->isDirectory()) {
2577- raiseFileError("FOFL0003", "The specified path does not point to a directory", lFile->getFilePath());
2578- }
2579-
2580- // actual list
2581+ String const path( getFilePathString( aArgs, 0 ) );
2582+
2583+ if ( fs::get_type( path ) != fs::directory )
2584+ raiseFileError( "FOFL0003", "path is not a directory", path );
2585+
2586 try {
2587- DirectoryIterator_t lIter = lFile->files();
2588- return ItemSequence_t(new IteratorBackedItemSequence(lIter, theModule->getItemFactory()));
2589- } catch (ZorbaException const& ze) {
2590- std::stringstream lSs;
2591- lSs << "An unknown error occured: " << ze.what() << "Can not list directory";
2592- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
2593- } catch (...) {
2594- //assert(false); if this happens errors are not proprly thrown
2595- raiseFileError("FOFL9999", "Can not list directory", lFile->getFilePath());
2596- }
2597-
2598- // dummy, this will never be called
2599- return ItemSequence_t(new EmptySequence());
2600+ return ItemSequence_t(
2601+ new IteratorBackedItemSequence( path, theModule->getItemFactory() )
2602+ );
2603+ }
2604+ catch ( std::exception const &e ) {
2605+ throw raiseFileError( "FOFL9999", e.what(), path );
2606+ }
2607 }
2608
2609 ListFunction::IteratorBackedItemSequence::IteratorBackedItemSequence(
2610- DirectoryIterator_t& aIter,
2611- ItemFactory* aFactory)
2612- : theIterator(aIter), theItemFactory(aFactory)
2613+ String const& path,
2614+ ItemFactory* aFactory
2615+) :
2616+ theIterator( path ),
2617+ theItemFactory( aFactory )
2618 {
2619 is_open = false;
2620 open_count = 0;
2621@@ -573,7 +473,7 @@
2622 void ListFunction::IteratorBackedItemSequence::open()
2623 {
2624 if (open_count) {
2625- theIterator->reset();
2626+ theIterator.reset();
2627 }
2628 open_count++;
2629 is_open = true;
2630@@ -592,64 +492,57 @@
2631 bool
2632 ListFunction::IteratorBackedItemSequence::next(Item& lItem)
2633 {
2634- std::string lPath;
2635- if (!theIterator->next(lPath)) {
2636+ if ( !theIterator.next() )
2637 return false;
2638- }
2639
2640- String lUriStr(lPath.c_str());
2641- lItem = theItemFactory->createString(lUriStr);
2642+ String lUriStr( theIterator->name );
2643+ lItem = theItemFactory->createString( lUriStr );
2644 return true;
2645 }
2646
2647 //*****************************************************************************
2648
2649-LastModifiedFunction::LastModifiedFunction(const FileModule* aModule)
2650- : FileFunction(aModule)
2651+LastModifiedFunction::LastModifiedFunction(const FileModule* aModule) :
2652+ FileFunction(aModule)
2653 {
2654 }
2655
2656 ItemSequence_t
2657 LastModifiedFunction::evaluate(
2658- const ExternalFunction::Arguments_t& aArgs,
2659- const StaticContext* aSctxCtx,
2660- const DynamicContext* aDynCtx) const
2661+ ExternalFunction::Arguments_t const &aArgs,
2662+ StaticContext const*,
2663+ DynamicContext const* ) const
2664 {
2665- String lFileStr = getFilePathString(aArgs, 0);
2666- File_t lFile = File::createFile(lFileStr.c_str());
2667-
2668- // precondition
2669- if (!lFile->exists()) {
2670- raiseFileError("FOFL0001", "A file or directory does not exist at this path", lFile->getFilePath());
2671- }
2672-
2673- // actual last modified
2674+ String const path( getFilePathString( aArgs, 0 ) );
2675+
2676+ fs::info info;
2677+ if ( !fs::get_type( path, &info ) )
2678+ raiseFileError( "FOFL0001", "file not found", path );
2679+
2680 try {
2681- time_t lTime = lFile->lastModified();
2682+ time_t lTime = info.mtime;
2683 // result of localtime needs to be copied.
2684 // Otherwise, nasty side effecs do happen
2685 struct tm lT(*localtime(&lTime));
2686 int gmtOffset = LastModifiedFunction::getGmtOffset();
2687
2688- return ItemSequence_t(new SingletonItemSequence(
2689- theModule->getItemFactory()->createDateTime(1900 + lT.tm_year,
2690- lT.tm_mon,
2691- lT.tm_mday,
2692- lT.tm_hour,
2693- lT.tm_min,
2694- lT.tm_sec,
2695- gmtOffset)));
2696- } catch (ZorbaException const& ze) {
2697- std::stringstream lSs;
2698- lSs << "An unknown error occured: " << ze.what() << "Can not retrieve the last modification timestamp of";
2699- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
2700- } catch (...) {
2701- //assert(false); if this happens errors are not proprly thrown
2702- raiseFileError("FOFL9999", "Can not retrieve the last modification timestamp of", lFile->getFilePath());
2703- }
2704-
2705- // dummy, this will never be called
2706- return ItemSequence_t(new EmptySequence());
2707+ return ItemSequence_t(
2708+ new SingletonItemSequence(
2709+ theModule->getItemFactory()->createDateTime(
2710+ 1900 + lT.tm_year,
2711+ lT.tm_mon,
2712+ lT.tm_mday,
2713+ lT.tm_hour,
2714+ lT.tm_min,
2715+ lT.tm_sec,
2716+ gmtOffset
2717+ )
2718+ )
2719+ );
2720+ }
2721+ catch ( std::exception const &e ) {
2722+ throw raiseFileError( "FOFL9999", e.what(), path );
2723+ }
2724 }
2725
2726 int
2727@@ -675,36 +568,20 @@
2728
2729 ItemSequence_t
2730 SizeFunction::evaluate(
2731- const ExternalFunction::Arguments_t& aArgs,
2732- const StaticContext* aSctxCtx,
2733- const DynamicContext* aDynCtx) const
2734+ ExternalFunction::Arguments_t const &aArgs,
2735+ StaticContext const*,
2736+ DynamicContext const* ) const
2737 {
2738- String lFileStr = getFilePathString(aArgs, 0);
2739- File_t lFile = File::createFile(lFileStr.c_str());
2740-
2741- // preconditions
2742- if (!lFile->exists()) {
2743- raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());
2744- }
2745- if (lFile->isDirectory()) {
2746- raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
2747- }
2748-
2749- // actual size
2750- File::FileSize_t lFs = -1;
2751- try {
2752- lFs = lFile->getSize();
2753- } catch (ZorbaException const& ze) {
2754- std::stringstream lSs;
2755- lSs << "An unknown error occured: " << ze.what() << "Can not retrieve the file size of";
2756- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
2757- } catch (...) {
2758- //assert(false); if this happens errors are not proprly thrown
2759- raiseFileError("FOFL9999", "Can not retrieve the file size of", lFile->getFilePath());
2760- }
2761+ String const path( getFilePathString( aArgs, 0 ) );
2762+
2763+ fs::info info;
2764+ if ( !fs::get_type( path, &info ) )
2765+ raiseFileError( "FOFL0001", "file not found", path );
2766+ if ( info.type != fs::file )
2767+ raiseFileError( "FOFL0004", "not plain file", path );
2768
2769 return ItemSequence_t(new SingletonItemSequence(
2770- theModule->getItemFactory()->createInteger(lFs)));
2771+ theModule->getItemFactory()->createInteger(info.size)));
2772 }
2773
2774 //*****************************************************************************
2775@@ -716,11 +593,16 @@
2776
2777 ItemSequence_t
2778 PathSeparator::evaluate(
2779- const ExternalFunction::Arguments_t& aArgs,
2780- const StaticContext* aSctxCtx,
2781- const DynamicContext* aDynCtx) const
2782+ ExternalFunction::Arguments_t const &aArgs,
2783+ StaticContext const*,
2784+ DynamicContext const* ) const
2785 {
2786- return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(FileFunction::pathSeparator())));
2787+ String const path_separator( 1, fs::path_separator );
2788+ return ItemSequence_t(
2789+ new SingletonItemSequence(
2790+ theModule->getItemFactory()->createString( path_separator )
2791+ )
2792+ );
2793 }
2794
2795 //*****************************************************************************
2796@@ -732,11 +614,16 @@
2797
2798 ItemSequence_t
2799 DirectorySeparator::evaluate(
2800- const ExternalFunction::Arguments_t& aArgs,
2801- const StaticContext* aSctxCtx,
2802- const DynamicContext* aDynCtx) const
2803+ ExternalFunction::Arguments_t const &aArgs,
2804+ StaticContext const*,
2805+ DynamicContext const* ) const
2806 {
2807- return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(FileFunction::directorySeparator())));
2808+ String const dir_separator( 1, fs::dir_separator );
2809+ return ItemSequence_t(
2810+ new SingletonItemSequence(
2811+ theModule->getItemFactory()->createString( dir_separator )
2812+ )
2813+ );
2814 }
2815
2816 //*****************************************************************************
2817@@ -748,11 +635,11 @@
2818
2819 ItemSequence_t
2820 ResolvePathFunction::evaluate(
2821- const ExternalFunction::Arguments_t& aArgs,
2822- const StaticContext* aSctxCtx,
2823- const DynamicContext* aDynCtx) const
2824+ ExternalFunction::Arguments_t const &aArgs,
2825+ StaticContext const*,
2826+ DynamicContext const* ) const
2827 {
2828- String lPathStr = getFilePathString(aArgs, 0);
2829+ String lPathStr = getFilePathString( aArgs, 0 );
2830 String lResult = pathToOSPath(lPathStr);
2831
2832 return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(lResult)));
2833@@ -766,17 +653,28 @@
2834 }
2835
2836 ItemSequence_t
2837-PathToNativeFunction::evaluate(const ExternalFunction::Arguments_t& args,
2838- const StaticContext* aSctxCtx,
2839- const DynamicContext* aDynCtx) const
2840+PathToNativeFunction::evaluate(
2841+ ExternalFunction::Arguments_t const &args,
2842+ StaticContext const*,
2843+ DynamicContext const* ) const
2844 {
2845 Item pathItem;
2846 Iterator_t arg0_iter = args[0]->getIterator();
2847 arg0_iter->open();
2848 arg0_iter->next(pathItem);
2849 arg0_iter->close();
2850- String osPath = filesystem_path::normalize_path(pathItem.getStringValue().c_str());
2851- return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(osPath)));
2852+ String const path( pathItem.getStringValue() );
2853+ try {
2854+ String const osPath( fs::normalize_path( path ) );
2855+ return ItemSequence_t(
2856+ new SingletonItemSequence(
2857+ theModule->getItemFactory()->createString( osPath )
2858+ )
2859+ );
2860+ }
2861+ catch ( std::invalid_argument const &e ) {
2862+ throw raiseFileError( "FOFL9999", e.what(), path );
2863+ }
2864 }
2865
2866 //*****************************************************************************
2867@@ -788,11 +686,11 @@
2868
2869 ItemSequence_t
2870 PathToUriFunction::evaluate(
2871- const ExternalFunction::Arguments_t& aArgs,
2872- const StaticContext* aSctxCtx,
2873- const DynamicContext* aDynCtx) const
2874+ ExternalFunction::Arguments_t const &aArgs,
2875+ StaticContext const*,
2876+ DynamicContext const* ) const
2877 {
2878- String lPathStr = getFilePathString(aArgs, 0);
2879+ String lPathStr = getFilePathString( aArgs, 0 );
2880 String lResult = pathToUriString(lPathStr);
2881
2882 return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createAnyURI(lResult)));
2883@@ -869,7 +767,8 @@
2884 //*****************************************************************************
2885
2886
2887-} /* namespace filemodule */ } /* namespace zorba */
2888+} // namespace filemodule
2889+} // namespace zorba
2890
2891 #ifdef WIN32
2892 # define DLL_EXPORT __declspec(dllexport)
2893
2894=== modified file 'modules/org/expath/ns/file.xq.src/file.h'
2895--- modules/org/expath/ns/file.xq.src/file.h 2013-03-06 02:54:03 +0000
2896+++ modules/org/expath/ns/file.xq.src/file.h 2013-06-11 16:49:27 +0000
2897@@ -16,6 +16,8 @@
2898 #ifndef ZORBA_FILEMODULE_FILE_H
2899 #define ZORBA_FILEMODULE_FILE_H
2900
2901+#include <zorba/util/fs_util.h>
2902+
2903 #include "file_function.h"
2904
2905 namespace zorba {
2906@@ -107,7 +109,7 @@
2907
2908 public:
2909 IteratorBackedItemSequence(
2910- DirectoryIterator_t& aIter,
2911+ String const& path,
2912 zorba::ItemFactory* aFactory);
2913
2914 virtual ~IteratorBackedItemSequence();
2915@@ -123,7 +125,7 @@
2916 private:
2917 bool is_open;
2918 int open_count;
2919- DirectoryIterator_t theIterator;
2920+ fs::iterator theIterator;
2921 ItemFactory* theItemFactory;
2922 };
2923 };
2924@@ -349,14 +351,14 @@
2925 class LinesItemSequence : public ItemSequence
2926 {
2927 protected:
2928- File_t theFile;
2929+ String theFile;
2930 String theEncoding;
2931 const ReadTextLinesFunction* theFunc;
2932
2933 class LinesIterator : public Iterator
2934 {
2935 protected:
2936- const File_t& theFile;
2937+ const String& theFile;
2938 const String& theEncoding;
2939 const ReadTextLinesFunction* theFunc;
2940
2941@@ -364,7 +366,7 @@
2942
2943 public:
2944 LinesIterator(
2945- const File_t&,
2946+ const String&,
2947 const String&,
2948 const ReadTextLinesFunction*);
2949
2950@@ -385,7 +387,7 @@
2951
2952 public:
2953 LinesItemSequence(
2954- const File_t& aFile,
2955+ const String& aFile,
2956 const String& aEncoding,
2957 const ReadTextLinesFunction*);
2958
2959
2960=== modified file 'modules/org/expath/ns/file.xq.src/file_function.cpp'
2961--- modules/org/expath/ns/file.xq.src/file_function.cpp 2013-02-07 17:24:36 +0000
2962+++ modules/org/expath/ns/file.xq.src/file_function.cpp 2013-06-11 16:49:27 +0000
2963@@ -20,11 +20,10 @@
2964
2965 #include <zorba/empty_sequence.h>
2966 #include <zorba/diagnostic_list.h>
2967-#include <zorba/file.h>
2968 #include <zorba/serializer.h>
2969 #include <zorba/store_consts.h>
2970 #include <zorba/user_exception.h>
2971-#include <zorba/util/path.h>
2972+#include <zorba/util/fs_util.h>
2973 #include <zorba/xquery_functions.h>
2974 #include <zorba/singleton_item_sequence.h>
2975 #include <zorba/zorba.h>
2976@@ -42,23 +41,6 @@
2977 #include <unistd.h>
2978 #endif
2979
2980-static zorba::String getCurrentPath()
2981-{
2982-#ifdef WIN32
2983- wchar_t* wbuffer = _wgetcwd(NULL, 0);
2984- char *buffer = (char*)malloc(1024);
2985- WideCharToMultiByte(CP_UTF8, 0, wbuffer, -1, buffer, 1024, NULL, NULL);
2986-#else
2987- char buffer[2048];
2988- getcwd(buffer, 2048);
2989-#endif
2990- zorba::String result(buffer);
2991-#ifdef WIN32
2992- free(buffer);
2993-#endif
2994- return result;
2995-}
2996-
2997 namespace zorba { namespace filemodule {
2998
2999 FileFunction::FileFunction(const FileModule* aModule)
3000@@ -70,16 +52,18 @@
3001 {
3002 }
3003
3004-void
3005+int
3006 FileFunction::raiseFileError(
3007- const std::string& aQName,
3008- const std::string& aMessage,
3009- const std::string& aPath) const
3010+ char const *aQName,
3011+ char const *aMessage,
3012+ String const &aPath ) const
3013 {
3014- std::stringstream lErrorMessage;
3015- lErrorMessage << aMessage << ": " << aPath;
3016- Item lQName = theModule->getItemFactory()->createQName(getURI(), "file", aQName);
3017- throw USER_EXCEPTION(lQName, lErrorMessage.str());
3018+ Item const lQName(
3019+ theModule->getItemFactory()->createQName( getURI(), "file", aQName )
3020+ );
3021+ std::ostringstream lErrorMessage;
3022+ lErrorMessage << '"' << aPath << "\": " << aMessage;
3023+ throw USER_EXCEPTION( lQName, lErrorMessage.str() );
3024 }
3025
3026 String
3027@@ -103,26 +87,22 @@
3028 }
3029 args_iter->close();
3030
3031- return (filesystem_path::normalize_path
3032- (lFileArg.c_str(), getCurrentPath().c_str()));
3033-}
3034-
3035-String
3036-FileFunction::directorySeparator() {
3037- return File::getDirectorySeparator();
3038-}
3039-
3040-String
3041-FileFunction::pathSeparator() {
3042- return File::getPathSeparator();
3043+ try {
3044+ return fs::normalize_path(lFileArg, fs::curdir());
3045+ }
3046+ catch ( std::invalid_argument const &e ) {
3047+ throw raiseFileError( "FOFL9999", e.what(), lFileArg );
3048+ }
3049 }
3050
3051 String
3052 FileFunction::pathToFullOSPath(const String& aPath) const {
3053- File_t lFile = File::createFile(aPath.c_str());
3054- std::string lPath = lFile->getFilePath();
3055-
3056- return String(lPath);
3057+ try {
3058+ return fs::normalize_path( aPath );
3059+ }
3060+ catch ( std::invalid_argument const &e ) {
3061+ throw raiseFileError( "FOFL9999", e.what(), aPath );
3062+ }
3063 }
3064
3065 String
3066@@ -147,31 +127,30 @@
3067
3068 String
3069 FileFunction::pathToOSPath(const String& aPath) const {
3070- File_t lFile = File::createFile(aPath.c_str());
3071- std::string lPath = lFile->getFilePath();
3072-
3073- return String(lPath);
3074+ try {
3075+ return fs::normalize_path( aPath );
3076+ }
3077+ catch ( std::invalid_argument const &e ) {
3078+ throw raiseFileError( "FOFL9999", e.what(), aPath );
3079+ }
3080 }
3081
3082 String
3083 FileFunction::pathToUriString(const String& aPath) const {
3084- std::stringstream lErrorMessage;
3085
3086- if(fn::starts_with(aPath,"file://")) {
3087+ if ( fn::starts_with( aPath,"file://" ) ) {
3088+ std::stringstream lErrorMessage;
3089 lErrorMessage << "Please provide a path, not a URI";
3090 Item lQName = theModule->getItemFactory()->createQName(
3091 "http://www.w3.org/2005/xqt-errors",
3092 "err",
3093 "XPTY0004");
3094- throw USER_EXCEPTION(lQName, lErrorMessage.str() );
3095+ throw USER_EXCEPTION( lQName, lErrorMessage.str() );
3096 }
3097
3098- File_t lFile = File::createFile(aPath.c_str());
3099-
3100- std::string lPath = lFile->getFileUri();
3101-
3102-
3103- return String(lPath);
3104+ String uri( aPath );
3105+
3106+ return uri;
3107 }
3108
3109 #ifdef WIN32
3110@@ -187,12 +166,9 @@
3111 return false;
3112 }
3113
3114- char lDrive = aString[0];
3115+ char const lDrive = aString[0];
3116 // the string is already upper case
3117- if (lDrive < 65 || lDrive > 90) {
3118- return false;
3119- }
3120- return true;
3121+ return lDrive >= 'A' && lDrive <= 'Z';
3122 }
3123 #endif
3124
3125@@ -234,33 +210,27 @@
3126 ItemSequence_t
3127 WriterFileFunction::evaluate(
3128 const ExternalFunction::Arguments_t& aArgs,
3129- const StaticContext* aSctxCtx,
3130- const DynamicContext* aDynCtx) const
3131+ const StaticContext*,
3132+ const DynamicContext* ) const
3133 {
3134- String lFileStr = getFilePathString(aArgs, 0);
3135- File_t lFile = File::createFile(lFileStr.c_str());
3136-
3137- // precondition
3138- if (lFile->isDirectory())
3139- {
3140- raiseFileError("FOFL0004",
3141- "The given path points to a directory", lFile->getFilePath());
3142- }
3143-
3144- bool lBinary = isBinary();
3145- // open the output stream in the desired write mode
3146- std::ofstream lOutStream;
3147-
3148- // actual write
3149- try
3150- {
3151- lFile->openOutputStream(lOutStream, lBinary, isAppend());
3152- }
3153- catch (ZorbaException& ze)
3154- {
3155- std::stringstream lSs;
3156- lSs << "Can not open file for writing: " << ze.what();
3157- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
3158+ String const lFileStr( getFilePathString(aArgs, 0) );
3159+
3160+ fs::type const fs_type = fs::get_type( lFileStr );
3161+ if ( fs_type && fs_type != fs::file )
3162+ raiseFileError( "FOFL0004", "not a plain file", lFileStr );
3163+
3164+ bool const lBinary = isBinary();
3165+
3166+ std::ios_base::openmode mode = std::ios_base::out
3167+ | (isAppend() ? std::ios_base::app : std::ios_base::trunc);
3168+ if ( lBinary )
3169+ mode |= std::ios_base::binary;
3170+
3171+ std::ofstream lOutStream( lFileStr.c_str(), mode );
3172+ if ( !lOutStream ) {
3173+ std::ostringstream oss;
3174+ oss << '"' << lFileStr << "\": can not open file for writing";
3175+ raiseFileError( "FOFL9999", oss.str().c_str(), lFileStr );
3176 }
3177
3178 // if this is a binary write
3179@@ -320,3 +290,4 @@
3180
3181 } // namespace filemodule
3182 } // namespace zorba
3183+/* vim:set et sw=2 ts=2: */
3184
3185=== modified file 'modules/org/expath/ns/file.xq.src/file_function.h'
3186--- modules/org/expath/ns/file.xq.src/file_function.h 2013-02-07 17:24:36 +0000
3187+++ modules/org/expath/ns/file.xq.src/file_function.h 2013-06-11 16:49:27 +0000
3188@@ -44,11 +44,11 @@
3189 protected:
3190 const FileModule* theModule;
3191
3192- void
3193+ int
3194 raiseFileError(
3195- const std::string& qName,
3196- const std::string& message,
3197- const std::string& path) const;
3198+ char const *qName,
3199+ char const *message,
3200+ const String& path) const;
3201
3202 /*
3203 * Gets the argument on position pos as a normalised file system path.
3204@@ -73,12 +73,6 @@
3205 String
3206 pathToUriString(const String& path) const;
3207
3208- static String
3209- directorySeparator();
3210-
3211- static String
3212- pathSeparator();
3213-
3214 public:
3215 FileFunction(const FileModule* module);
3216 ~FileFunction();
3217
3218=== modified file 'src/api/CMakeLists.txt'
3219--- src/api/CMakeLists.txt 2013-04-10 10:13:31 +0000
3220+++ src/api/CMakeLists.txt 2013-06-11 16:49:27 +0000
3221@@ -63,11 +63,6 @@
3222 module_info_impl.cpp
3223 )
3224
3225-IF (ZORBA_WITH_FILE_ACCESS)
3226- LIST(APPEND API_SRCS
3227- fileimpl.cpp)
3228-ENDIF (ZORBA_WITH_FILE_ACCESS)
3229-
3230 IF (NOT ZORBA_NO_FULL_TEXT)
3231 LIST(APPEND API_SRCS
3232 stemmer.cpp
3233
3234=== removed file 'src/api/fileimpl.cpp'
3235--- src/api/fileimpl.cpp 2013-04-19 22:25:21 +0000
3236+++ src/api/fileimpl.cpp 1970-01-01 00:00:00 +0000
3237@@ -1,404 +0,0 @@
3238-/*
3239- * Copyright 2006-2008 The FLWOR Foundation.
3240- *
3241- * Licensed under the Apache License, Version 2.0 (the "License");
3242- * you may not use this file except in compliance with the License.
3243- * You may obtain a copy of the License at
3244- *
3245- * http://www.apache.org/licenses/LICENSE-2.0
3246- *
3247- * Unless required by applicable law or agreed to in writing, software
3248- * distributed under the License is distributed on an "AS IS" BASIS,
3249- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3250- * See the License for the specific language governing permissions and
3251- * limitations under the License.
3252- */
3253-#include "stdafx.h"
3254-
3255-#include "fileimpl.h"
3256-
3257-#include <fstream>
3258-
3259-#include <zorba/diagnostic_handler.h>
3260-#include <zorba/util/file.h>
3261-
3262-#include <runtime/util/flowctl_exception.h>
3263-
3264-#include "diagnostics/xquery_diagnostics.h"
3265-
3266-#ifdef WIN32
3267-#include <util/ascii_util.h>
3268-#endif
3269-
3270-#include "util/uri_util.h"
3271-#include "zorbaimpl.h"
3272-
3273-namespace zorba {
3274-
3275-DirectoryIteratorImpl::DirectoryIteratorImpl(std::string const& aPath) :
3276- theInternalDirIter( aPath.c_str() )
3277-{
3278-}
3279-
3280-bool
3281-DirectoryIteratorImpl::next(std::string& aPathStr) const
3282-{
3283- if (!theInternalDirIter.next()) {
3284- return false;
3285- }
3286-
3287- // get the current pointed entry
3288- aPathStr = theInternalDirIter.entry_name();
3289-
3290- return true;
3291-}
3292-
3293-void DirectoryIteratorImpl::reset()
3294-{
3295- theInternalDirIter.reset();
3296-}
3297-
3298-FileImpl::FileImpl(std::string const& path)
3299- : theDiagnosticHandler(new DiagnosticHandler())
3300-{
3301- theInternalFile = new file(path
3302-#ifdef WIN32
3303- , filesystem_path::CONVERT_SLASHES
3304-#endif
3305- );
3306-}
3307-
3308-FileImpl::~FileImpl()
3309-{
3310- delete theInternalFile;
3311- delete theDiagnosticHandler;
3312-}
3313-
3314-File_t
3315-File::createFile(const std::string& path)
3316-{
3317- return new FileImpl(path);
3318-}
3319-
3320-const char*
3321-File::getDirectorySeparator()
3322-{
3323- return filesystem_path::get_directory_separator();
3324-}
3325-
3326-const char*
3327-File::getPathSeparator()
3328-{
3329- return filesystem_path::get_path_separator();
3330-}
3331-
3332-const std::string
3333-FileImpl::getFilePath() const
3334-{
3335- std::string lResult;
3336-
3337- ZORBA_TRY
3338- lResult = theInternalFile->get_path();
3339- ZORBA_CATCH
3340-
3341- return lResult;
3342-}
3343-
3344-const std::string
3345-FileImpl::getFileUri() const
3346-{
3347- std::string lPath;
3348-
3349- ZORBA_TRY
3350- lPath = theInternalFile->get_path();
3351-#ifdef WIN32
3352- ascii::replace_all( lPath, '\\', '/' );
3353-#endif
3354-
3355- std::stringstream lEncodedResult;
3356- lEncodedResult << "file:///";
3357-
3358- size_t lCurrentPos = 0;
3359- size_t lNextSlashPos = lPath.find_first_of("/");
3360- while (lNextSlashPos != std::string::npos) {
3361- String lEncodedSegment(lPath.substr(lCurrentPos, lNextSlashPos - lCurrentPos));
3362- uri::encode( lEncodedSegment );
3363- lEncodedResult << lEncodedSegment << "/";
3364- lCurrentPos = lNextSlashPos + 1;
3365- lNextSlashPos = lPath.find_first_of("/", lNextSlashPos + 1);
3366- }
3367-
3368- String lEncodedSegment(lPath.substr(lCurrentPos));
3369- uri::encode( lEncodedSegment );
3370- lEncodedResult << lEncodedSegment;
3371-
3372- lPath = lEncodedResult.str();
3373- ZORBA_CATCH
3374-
3375- return lPath;
3376-}
3377-
3378-bool
3379-FileImpl::isDirectory( bool follow_symlinks ) const
3380-{
3381- bool lResult = false;
3382-
3383- ZORBA_TRY
3384- lResult = theInternalFile->is_directory( follow_symlinks )
3385- || theInternalFile->is_volume( follow_symlinks )
3386- || theInternalFile->is_root();
3387- ZORBA_CATCH
3388-
3389- return lResult;
3390-}
3391-
3392-bool
3393-FileImpl::isFile( bool follow_symlinks ) const
3394-{
3395- bool lResult = false;
3396-
3397- ZORBA_TRY
3398- lResult = theInternalFile->is_file( follow_symlinks ) || theInternalFile->is_link();
3399- ZORBA_CATCH
3400-
3401- return lResult;
3402-}
3403-
3404-bool
3405-FileImpl::isLink() const
3406-{
3407- bool lResult = false;
3408-
3409- ZORBA_TRY
3410- lResult = theInternalFile->is_link();
3411- ZORBA_CATCH
3412-
3413- return lResult;
3414-}
3415-
3416-bool
3417-FileImpl::isVolume( bool follow_symlinks ) const
3418-{
3419- bool lResult = false;
3420-
3421- ZORBA_TRY
3422- lResult = theInternalFile->is_volume( follow_symlinks );
3423- ZORBA_CATCH
3424-
3425- return lResult;
3426-}
3427-
3428-bool
3429-FileImpl::isInvalid() const
3430-{
3431- bool lResult = false;
3432-
3433- ZORBA_TRY
3434- lResult = theInternalFile->is_invalid();
3435- ZORBA_CATCH
3436-
3437- return lResult;
3438-}
3439-
3440-bool
3441-FileImpl::exists( bool follow_symlinks ) const
3442-{
3443- bool lResult = false;
3444-
3445- ZORBA_TRY
3446- lResult = theInternalFile->exists( follow_symlinks );
3447- ZORBA_CATCH
3448-
3449- return lResult;
3450-}
3451-
3452-void
3453-FileImpl::remove()
3454-{
3455- ZORBA_TRY
3456- if (theInternalFile->is_directory()) {
3457- theInternalFile->rmdir(false);
3458- } else {
3459- theInternalFile->remove(false);
3460- }
3461- ZORBA_CATCH
3462-}
3463-
3464-bool
3465-FileImpl::create()
3466-{
3467- bool lResult = false;
3468-
3469- ZORBA_TRY
3470- // if the file/dir exist, return false
3471- if (theInternalFile->exists()) {
3472- return false;
3473- }
3474-
3475- theInternalFile->create();
3476-
3477- // if the file does not exist, return false
3478- if (!theInternalFile->exists() || !theInternalFile->is_file()) {
3479- return false;
3480- }
3481-
3482- lResult = true;
3483- ZORBA_CATCH
3484-
3485- return lResult;
3486-}
3487-
3488-bool
3489-FileImpl::rename(std::string const& newpath)
3490-{
3491- bool lResult = false;
3492-
3493- ZORBA_TRY
3494- // if the file/dir does not exist, return false
3495- if (!theInternalFile->exists()) {
3496- return false;
3497- }
3498- // if the new path is already used, return false
3499- file lNewFile(newpath);
3500- if (lNewFile.exists()) {
3501- return false;
3502- }
3503-
3504- theInternalFile->rename(newpath);
3505-
3506- // if the file does not exist, return false
3507- if (!lNewFile.exists()) {
3508- return false;
3509- }
3510-
3511- lResult = true;
3512- ZORBA_CATCH
3513-
3514- return lResult;
3515-}
3516-
3517-File::FileSize_t
3518-FileImpl::getSize() const
3519-{
3520- ZORBA_TRY
3521- return theInternalFile->get_size();
3522- ZORBA_CATCH
3523- assert(false);
3524- return -1;
3525-}
3526-
3527-void
3528-FileImpl::mkdir(bool aRecursive)
3529-{
3530- ZORBA_TRY
3531- if (aRecursive) {
3532- theInternalFile->deep_mkdir();
3533- } else {
3534- theInternalFile->mkdir();
3535- }
3536- ZORBA_CATCH
3537-}
3538-
3539-DirectoryIterator_t
3540-FileImpl::files() const
3541-{
3542- return new DirectoryIteratorImpl(theInternalFile->get_path());
3543-}
3544-
3545-void
3546-FileImpl::openInputStream(std::ifstream& aInStream, bool binary, bool trimByteOrderMark) const
3547-{
3548- ZORBA_TRY
3549- std::string lPath(theInternalFile->get_path());
3550-
3551- if (!theInternalFile->exists())
3552- throw XQUERY_EXCEPTION(
3553- err::FODC0002, ERROR_PARAMS( lPath, ZED( FileNotFoundOrReadable ) )
3554- );
3555- if (!theInternalFile->is_file())
3556- throw XQUERY_EXCEPTION(
3557- err::FODC0002, ERROR_PARAMS( lPath, ZED( NotPlainFile ) )
3558- );
3559-
3560- std::ios_base::openmode lMode = std::ifstream::in;
3561- if (binary) {
3562- lMode |= std::ios_base::binary;
3563- }
3564-#ifndef WIN32
3565- aInStream.open(lPath.c_str(), lMode);
3566-#else
3567- WCHAR wpath_str[1024];
3568- wpath_str[0] = 0;
3569- if(MultiByteToWideChar(CP_UTF8,
3570- 0, lPath.c_str(), -1,
3571- wpath_str, sizeof(wpath_str)/sizeof(WCHAR)) == 0)
3572- {//probably there is some invalid utf8 char, try the Windows ACP
3573- MultiByteToWideChar(CP_ACP,
3574- 0, lPath.c_str(), -1,
3575- wpath_str, sizeof(wpath_str)/sizeof(WCHAR));
3576- }
3577- aInStream.open(wpath_str, lMode);
3578-#endif
3579-
3580- if (aInStream.is_open() == false)
3581- throw XQUERY_EXCEPTION(
3582- err::FODC0002, ERROR_PARAMS( lPath, ZED( FileNotFoundOrReadable ) )
3583- );
3584-
3585- if (trimByteOrderMark) {
3586- char lBuf[3];
3587- aInStream.read(lBuf, 3);
3588- if (!aInStream.good() || lBuf[0] != (char)0xEF || lBuf[1] != (char)0xBB || lBuf[2] != (char)0xBF ) {
3589- aInStream.seekg(0);
3590- }
3591- }
3592- ZORBA_CATCH
3593-}
3594-
3595-void
3596-FileImpl::openOutputStream(std::ofstream& aOutStream, bool binary, bool append) const
3597-{
3598- ZORBA_TRY
3599- std::string lPath(theInternalFile->get_path());
3600-
3601- if (theInternalFile->exists() && !theInternalFile->is_file())
3602- throw XQUERY_EXCEPTION(
3603- err::FODC0002, ERROR_PARAMS( lPath, ZED( NotPlainFile ) )
3604- );
3605-
3606- std::ios_base::openmode lMode = std::ifstream::out;
3607- lMode |= append ? std::ios_base::app : std::ios_base::trunc;
3608- if (binary) {
3609- lMode |= std::ios_base::binary;
3610- }
3611-#ifndef WIN32
3612- aOutStream.open(lPath.c_str(), lMode);
3613-#else
3614- WCHAR wpath_str[1024];
3615- wpath_str[0] = 0;
3616- if(MultiByteToWideChar(CP_UTF8,
3617- 0, lPath.c_str(), -1,
3618- wpath_str, sizeof(wpath_str)/sizeof(WCHAR)) == 0)
3619- {//probably there is some invalid utf8 char, try the Windows ACP
3620- MultiByteToWideChar(CP_ACP,
3621- 0, lPath.c_str(), -1,
3622- wpath_str, sizeof(wpath_str)/sizeof(WCHAR));
3623- }
3624- aOutStream.open(wpath_str, lMode);
3625-#endif
3626-
3627- if (aOutStream.is_open() == false)
3628- throw XQUERY_EXCEPTION(
3629- err::FODC0002, ERROR_PARAMS( lPath, ZED( FileNotFoundOrReadable ) )
3630- );
3631- ZORBA_CATCH
3632-}
3633-
3634-time_t
3635-FileImpl::lastModified() const
3636-{
3637- return theInternalFile->lastModified();
3638-}
3639-
3640-} // namespace zorba
3641-/* vim:set et sw=2 ts=2: */
3642
3643=== removed file 'src/api/fileimpl.h'
3644--- src/api/fileimpl.h 2013-04-19 22:25:21 +0000
3645+++ src/api/fileimpl.h 1970-01-01 00:00:00 +0000
3646@@ -1,94 +0,0 @@
3647-/*
3648- * Copyright 2006-2008 The FLWOR Foundation.
3649- *
3650- * Licensed under the Apache License, Version 2.0 (the "License");
3651- * you may not use this file except in compliance with the License.
3652- * You may obtain a copy of the License at
3653- *
3654- * http://www.apache.org/licenses/LICENSE-2.0
3655- *
3656- * Unless required by applicable law or agreed to in writing, software
3657- * distributed under the License is distributed on an "AS IS" BASIS,
3658- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3659- * See the License for the specific language governing permissions and
3660- * limitations under the License.
3661- */
3662-#pragma once
3663-#ifndef XQP_FILE_IMPL_H
3664-#define XQP_FILE_IMPL_H
3665-
3666-#include <iostream>
3667-#include <zorba/file.h>
3668-
3669-#include "util/fs_util.h"
3670-
3671-namespace zorba {
3672-
3673- class file;
3674- class DiagnosticHandler;
3675-
3676-
3677-class DirectoryIteratorImpl : public DirectoryIterator
3678-{
3679-private:
3680-
3681- mutable fs::iterator theInternalDirIter;
3682-
3683-public:
3684-
3685- DirectoryIteratorImpl(std::string const& aPath);
3686-
3687- bool next(std::string& aPathStr) const;
3688- void reset();
3689-};
3690-
3691-
3692-class FileImpl : public File
3693-{
3694-private:
3695-
3696- zorba::file* theInternalFile;
3697-
3698- DiagnosticHandler* theDiagnosticHandler;
3699-
3700-public:
3701-
3702- FileImpl(std::string const& _path);
3703-
3704- ~FileImpl();
3705-
3706-
3707-public: // public methods
3708-
3709- const std::string getFilePath() const;
3710- const std::string getFileUri() const;
3711-
3712- bool isDirectory( bool follow_symlinks = true ) const;
3713- bool isFile( bool follow_symlinks = true ) const;
3714- bool isLink() const;
3715- bool isVolume( bool follow_symlinks = true ) const;
3716- bool isInvalid() const; // deprecated
3717- bool exists( bool follow_symlinks = true ) const;
3718-
3719- void remove();
3720- bool create();
3721- bool rename(std::string const& newpath);
3722-
3723- FileSize_t getSize() const;
3724-
3725- void mkdir(bool recursive = true);
3726-
3727- DirectoryIterator_t files() const;
3728-
3729- void openInputStream(std::ifstream& aInStream, bool binary, bool trimByteOrderMark) const;
3730-
3731- void openOutputStream(std::ofstream& aOutStream, bool binary, bool append) const;
3732-
3733- time_t lastModified() const;
3734-};
3735-
3736-
3737-} /* namespace zorba */
3738-
3739-#endif
3740-/* vim:set et sw=2 ts=2: */
3741
3742=== modified file 'src/api/staticcontextimpl.cpp'
3743--- src/api/staticcontextimpl.cpp 2013-03-25 23:02:19 +0000
3744+++ src/api/staticcontextimpl.cpp 2013-06-11 16:49:27 +0000
3745@@ -23,7 +23,7 @@
3746 #include <zorba/diagnostic_handler.h>
3747 #include <zorba/static_context_consts.h>
3748 #include <zorba/typeident.h>
3749-#include <zorba/util/path.h>
3750+#include <zorba/util/fs_util.h>
3751 #include <zorba/empty_sequence.h>
3752 #include <zorba/singleton_item_sequence.h>
3753
3754@@ -1131,9 +1131,9 @@
3755 {
3756 aInternalStrings.push_back(Unmarshaller::getInternalString(*lIter).c_str());
3757 zstring& lPath = aInternalStrings.back();
3758- if (lPath[lPath.length() - 1] != *filesystem_path::get_directory_separator())
3759+ if (lPath[lPath.length() - 1] != fs::dir_separator)
3760 {
3761- lPath.append(filesystem_path::get_directory_separator());
3762+ lPath += fs::dir_separator;
3763 }
3764 }
3765 }
3766
3767=== modified file 'src/api/stemmer_wrappers.cpp'
3768--- src/api/stemmer_wrappers.cpp 2013-02-07 17:24:36 +0000
3769+++ src/api/stemmer_wrappers.cpp 2013-06-11 16:49:27 +0000
3770@@ -19,9 +19,9 @@
3771
3772 #ifndef ZORBA_NO_FULL_TEXT
3773
3774+#include <zorba/internal/cxx_util.h>
3775 #include "api/unmarshaller.h"
3776 #include "diagnostics/assert.h"
3777-#include "util/cxx_util.h"
3778
3779 #include "stemmer_wrappers.h"
3780
3781
3782=== modified file 'src/api/thesaurus_wrappers.cpp'
3783--- src/api/thesaurus_wrappers.cpp 2013-02-07 17:24:36 +0000
3784+++ src/api/thesaurus_wrappers.cpp 2013-06-11 16:49:27 +0000
3785@@ -19,9 +19,9 @@
3786
3787 #ifndef ZORBA_NO_FULL_TEXT
3788
3789+#include <zorba/internal/cxx_util.h>
3790 #include "api/unmarshaller.h"
3791 #include "diagnostics/assert.h"
3792-#include "util/cxx_util.h"
3793
3794 #include "thesaurus_wrappers.h"
3795
3796
3797=== modified file 'src/api/zorba_string.cpp'
3798--- src/api/zorba_string.cpp 2013-02-07 17:24:36 +0000
3799+++ src/api/zorba_string.cpp 2013-06-11 16:49:27 +0000
3800@@ -15,11 +15,11 @@
3801 */
3802 #include "stdafx.h"
3803
3804+#include <zorba/internal/cxx_util.h>
3805 #include <zorba/zorba_string.h>
3806
3807 #include "api/unmarshaller.h"
3808 #include "util/ascii_util.h"
3809-#include "util/cxx_util.h"
3810 #include "util/regex.h"
3811 #include "util/string_util.h"
3812 #include "util/uri_util.h"
3813
3814=== modified file 'src/compiler/expression/ftnode.cpp'
3815--- src/compiler/expression/ftnode.cpp 2013-02-07 17:24:36 +0000
3816+++ src/compiler/expression/ftnode.cpp 2013-06-11 16:49:27 +0000
3817@@ -16,11 +16,11 @@
3818 #include "stdafx.h"
3819
3820 #include <zorba/error.h>
3821+#include <zorba/internal/cxx_util.h>
3822
3823 #include "diagnostics/xquery_diagnostics.h"
3824 #include "types/casting.h"
3825 #include "util/ascii_util.h"
3826-#include "util/cxx_util.h"
3827 #include "util/indent.h"
3828 #include "util/stl_util.h"
3829 #include "zorbautils/locale.h"
3830
3831=== modified file 'src/compiler/expression/ftnode.h'
3832--- src/compiler/expression/ftnode.h 2013-02-07 17:24:36 +0000
3833+++ src/compiler/expression/ftnode.h 2013-06-11 16:49:27 +0000
3834@@ -18,6 +18,7 @@
3835 #define ZORBA_COMPILER_FTNODE_H
3836
3837 #include <zorba/locale.h>
3838+#include <zorba/internal/cxx_util.h>
3839
3840 #include "common/shared_types.h"
3841
3842@@ -29,8 +30,6 @@
3843
3844 #include "runtime/base/plan_iterator.h"
3845
3846-#include "util/cxx_util.h"
3847-
3848 #include "zorbatypes/rchandle.h"
3849 #include "zorbatypes/zstring.h"
3850
3851
3852=== modified file 'src/compiler/expression/ftnode_visitor.cpp'
3853--- src/compiler/expression/ftnode_visitor.cpp 2013-02-07 17:24:36 +0000
3854+++ src/compiler/expression/ftnode_visitor.cpp 2013-06-11 16:49:27 +0000
3855@@ -15,7 +15,7 @@
3856 */
3857 #include "stdafx.h"
3858
3859-#include "util/cxx_util.h"
3860+#include <zorba/internal/cxx_util.h>
3861
3862 #include "expr_visitor.h"
3863 #include "ftnode.h"
3864
3865=== modified file 'src/compiler/parser/ft_types.cpp'
3866--- src/compiler/parser/ft_types.cpp 2013-02-07 17:24:36 +0000
3867+++ src/compiler/parser/ft_types.cpp 2013-06-11 16:49:27 +0000
3868@@ -15,7 +15,7 @@
3869 */
3870 #include "stdafx.h"
3871
3872-#include "util/cxx_util.h"
3873+#include <zorba/internal/cxx_util.h>
3874
3875 #include "ft_types.h"
3876
3877
3878=== modified file 'src/context/default_uri_mappers.cpp'
3879--- src/context/default_uri_mappers.cpp 2013-02-07 17:24:36 +0000
3880+++ src/context/default_uri_mappers.cpp 2013-06-11 16:49:27 +0000
3881@@ -180,7 +180,7 @@
3882 // If module-path entry is relative, normalize it against the
3883 // static context's base URI.
3884 if (!fs::is_absolute(*lIter)) {
3885- zstring lAbsPath = fs::get_normalized_path(*lIter, aSctx.get_base_uri());
3886+ zstring lAbsPath = fs::normalize_path(*lIter, aSctx.get_base_uri());
3887 lCandidateURI.append(lAbsPath);
3888 }
3889 else {
3890
3891=== modified file 'src/context/default_url_resolvers.cpp'
3892--- src/context/default_url_resolvers.cpp 2013-02-07 17:24:36 +0000
3893+++ src/context/default_url_resolvers.cpp 2013-06-11 16:49:27 +0000
3894@@ -15,9 +15,9 @@
3895 */
3896 #include "stdafx.h"
3897
3898+#include <zorba/internal/cxx_util.h>
3899
3900 #include "context/default_url_resolvers.h"
3901-#include "util/cxx_util.h"
3902 #include "util/uri_util.h"
3903 #include "util/http_util.h"
3904 #include "util/fs_util.h"
3905@@ -125,13 +125,18 @@
3906 if (lScheme != uri::file) {
3907 return NULL;
3908 }
3909- zstring lPath = fs::get_normalized_path(aUrl);
3910- if (fs::get_type(lPath) == fs::file) {
3911- std::ifstream* lStream = new std::ifstream(lPath.c_str());
3912- return new StreamResource(
3913- lStream, &fileStreamReleaser, "", true /* seekable */);
3914- }
3915- return NULL;
3916+ try {
3917+ std::string lPath( fs::normalize_path(aUrl) );
3918+ if (fs::get_type(lPath) == fs::file) {
3919+ std::ifstream* lStream = new std::ifstream(lPath.c_str());
3920+ return new StreamResource(
3921+ lStream, &fileStreamReleaser, "", true /* seekable */);
3922+ }
3923+ return NULL;
3924+ }
3925+ catch ( std::invalid_argument const &e ) {
3926+ throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
3927+ }
3928 }
3929
3930 /******
3931
3932=== modified file 'src/context/dynamic_loader.cpp'
3933--- src/context/dynamic_loader.cpp 2013-02-07 17:24:36 +0000
3934+++ src/context/dynamic_loader.cpp 2013-06-11 16:49:27 +0000
3935@@ -28,14 +28,15 @@
3936 #ifdef WIN32
3937 # include <strsafe.h>
3938 #endif
3939-
3940-#include <diagnostics/xquery_diagnostics.h>
3941-#include <zorbatypes/URI.h>
3942+#include <fstream>
3943+
3944+#include "diagnostics/xquery_diagnostics.h"
3945+#include "zorbatypes/URI.h"
3946+
3947 #include <zorba/external_module.h>
3948 #include <zorba/zorba_string.h>
3949 #include <context/get_current_lib_suffix.h>
3950-#include <fstream>
3951-#include <util/error_util.h>
3952+#include <zorba/util/error_util.h>
3953
3954 namespace zorba {
3955
3956
3957=== modified file 'src/diagnostics/assert.h'
3958--- src/diagnostics/assert.h 2013-02-07 17:24:36 +0000
3959+++ src/diagnostics/assert.h 2013-06-11 16:49:27 +0000
3960@@ -22,7 +22,7 @@
3961
3962 #include <sstream>
3963
3964-#include "util/cxx_util.h"
3965+#include <zorba/internal/cxx_util.h>
3966
3967 namespace zorba {
3968
3969
3970=== modified file 'src/diagnostics/diagnostic_en.xml'
3971--- src/diagnostics/diagnostic_en.xml 2013-06-04 00:34:52 +0000
3972+++ src/diagnostics/diagnostic_en.xml 2013-06-11 16:49:27 +0000
3973@@ -4061,10 +4061,6 @@
3974 <value>promotion not possible</value>
3975 </entry>
3976
3977- <entry key="QuotedColon_23">
3978- <value>"$2": $3</value>
3979- </entry>
3980-
3981 <entry key="SEPM0009_Not10">
3982 <value>the version parameter has a value other than "1.0" and the doctype-system parameter is specified</value>
3983 </entry>
3984
3985=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
3986--- src/diagnostics/pregenerated/dict_en.cpp 2013-06-04 01:32:30 +0000
3987+++ src/diagnostics/pregenerated/dict_en.cpp 2013-06-11 16:49:27 +0000
3988@@ -779,7 +779,6 @@
3989 { "~ParseFragmentInvalidOptions", "invalid options passed to the parse-xml:parse() function, the element must be in the schema target namespace" },
3990 { "~ParseFragmentOptionCombinationNotAllowed", "only one of the <schema-validate/>, <DTD-validate/> or <parse-external-parsed-entity/> options can be specified" },
3991 { "~PromotionImpossible", "promotion not possible" },
3992- { "~QuotedColon_23", "\"$2\": $3" },
3993 #if defined(ZORBA_NO_ICU)
3994 { "~REGEX_BROKEN_PIs_CONSTRUCT", "broken \\\\p{Is} construct; valid characters are [a-zA-Z0-9-]" },
3995 #endif
3996
3997=== modified file 'src/diagnostics/pregenerated/dict_zed_keys.h'
3998--- src/diagnostics/pregenerated/dict_zed_keys.h 2013-05-16 22:26:07 +0000
3999+++ src/diagnostics/pregenerated/dict_zed_keys.h 2013-06-11 16:49:27 +0000
4000@@ -319,7 +319,6 @@
4001 #define ZED_XMLParserInitFailed "~XMLParserInitFailed"
4002 #define ZED_XMLParserNoCreateTree "~XMLParserNoCreateTree"
4003 #define ZED_PromotionImpossible "~PromotionImpossible"
4004-#define ZED_QuotedColon_23 "~QuotedColon_23"
4005 #define ZED_SEPM0009_Not10 "~SEPM0009_Not10"
4006 #define ZED_SEPM0009_NotOmit "~SEPM0009_NotOmit"
4007 #define ZED_SchemaUnexpected "~SchemaUnexpected"
4008
4009=== modified file 'src/diagnostics/user_exception.h'
4010--- src/diagnostics/user_exception.h 2013-02-07 17:24:36 +0000
4011+++ src/diagnostics/user_exception.h 2013-06-11 16:49:27 +0000
4012@@ -18,13 +18,13 @@
4013 #ifndef ZORBA_USER_EXCEPTION_H
4014 #define ZORBA_USER_EXCEPTION_H
4015
4016+#include <zorba/internal/cxx_util.h>
4017 #include <zorba/item.h>
4018 #include <zorba/user_exception.h>
4019
4020 #include "api/unmarshaller.h"
4021 #include "compiler/parser/query_loc.h"
4022 #include "store/api/item.h"
4023-#include "util/cxx_util.h"
4024 #include "util/stl_util.h"
4025
4026 namespace zorba {
4027
4028=== modified file 'src/diagnostics/xquery_diagnostics.h'
4029--- src/diagnostics/xquery_diagnostics.h 2013-02-07 17:24:36 +0000
4030+++ src/diagnostics/xquery_diagnostics.h 2013-06-11 16:49:27 +0000
4031@@ -22,12 +22,11 @@
4032
4033 #include <zorba/config.h>
4034 #include <zorba/internal/unique_ptr.h>
4035+#include <zorba/util/error_util.h>
4036
4037 // TODO: this #include is temporary
4038 #include <zorba/diagnostic_list.h>
4039
4040-#include "util/error_util.h"
4041-
4042 #include "diagnostic.h"
4043 #include "dict.h"
4044 #include "xquery_exception.h"
4045
4046=== modified file 'src/diagnostics/xquery_exception.cpp'
4047--- src/diagnostics/xquery_exception.cpp 2013-05-24 00:27:45 +0000
4048+++ src/diagnostics/xquery_exception.cpp 2013-06-11 16:49:27 +0000
4049@@ -279,7 +279,7 @@
4050 case uri::file:
4051 try {
4052 o << (as_xml ? " uri=\"" : "<")
4053- << fs::get_normalized_path( uri )
4054+ << fs::normalize_path( uri )
4055 << (as_xml ? '"' : '>');
4056 break;
4057 }
4058
4059=== modified file 'src/precompiled/stdafx.h'
4060--- src/precompiled/stdafx.h 2013-04-17 18:37:33 +0000
4061+++ src/precompiled/stdafx.h 2013-06-11 16:49:27 +0000
4062@@ -31,6 +31,7 @@
4063 #include <set>
4064 #include <sys/timeb.h>
4065
4066+ #include <zorba/internal/cxx_util.h>
4067 #include "runtime/sequences/sequences.h"
4068 #include "diagnostics/xquery_diagnostics.h"
4069 #include "xercesc/util/xercesdefs.hpp"
4070@@ -48,7 +49,6 @@
4071 #include <zorba/store_manager.h>
4072 #include <zorba/xquery.h>
4073 #include <zorba/xquery_exception.h>
4074- #include "util/cxx_util.h"
4075 #include "diagnostics/assert.h"
4076 #include "zorbatypes/mapm/m_apm_lc.h"
4077 #include "zorbatypes/datetime/parse.h"
4078
4079=== modified file 'src/runtime/full_text/apply.cpp'
4080--- src/runtime/full_text/apply.cpp 2013-06-07 21:22:39 +0000
4081+++ src/runtime/full_text/apply.cpp 2013-06-11 16:49:27 +0000
4082@@ -19,17 +19,17 @@
4083 #include <set>
4084 #include <vector>
4085
4086+#include <zorba/internal/cxx_util.h>
4087 #include <zorba/tokenizer.h>
4088-#include <context/uri_resolver.h>
4089
4090 #include "compiler/expression/ftnode.h"
4091+#include "context/uri_resolver.h"
4092 #include "diagnostics/dict.h"
4093 #include "diagnostics/xquery_diagnostics.h"
4094 #include "store/api/item.h"
4095 #include "store/api/item_factory.h"
4096 #include "store/api/store.h"
4097 #include "system/globalenv.h"
4098-#include "util/cxx_util.h"
4099 #include "util/indent.h"
4100 #include "util/stl_util.h"
4101 #include "zorbamisc/ns_consts.h"
4102
4103=== modified file 'src/runtime/full_text/ft_module_util.h'
4104--- src/runtime/full_text/ft_module_util.h 2012-06-24 14:44:40 +0000
4105+++ src/runtime/full_text/ft_module_util.h 2013-06-11 16:49:27 +0000
4106@@ -23,12 +23,12 @@
4107 // needs to be #include'd into the .cpp generated from the ft_module.xml file.
4108 //
4109
4110+#include <deque>
4111+
4112+#include <zorba/internal/cxx_util.h>
4113 #include <zorba/tokenizer.h>
4114
4115-#include <deque>
4116-
4117 #include "store/api/item.h"
4118-#include "util/cxx_util.h"
4119 #include "zorbatypes/ft_token.h"
4120
4121 #include "ft_module_util.h"
4122
4123=== modified file 'src/runtime/full_text/ft_query_item.cpp'
4124--- src/runtime/full_text/ft_query_item.cpp 2013-02-07 17:24:36 +0000
4125+++ src/runtime/full_text/ft_query_item.cpp 2013-06-11 16:49:27 +0000
4126@@ -15,7 +15,8 @@
4127 */
4128 #include "stdafx.h"
4129
4130-#include "util/cxx_util.h"
4131+#include <zorba/internal/cxx_util.h>
4132+
4133 #include "util/stl_util.h"
4134 #include "diagnostics/assert.h"
4135
4136
4137=== modified file 'src/runtime/full_text/ft_stop_words_set.cpp'
4138--- src/runtime/full_text/ft_stop_words_set.cpp 2013-02-07 17:24:36 +0000
4139+++ src/runtime/full_text/ft_stop_words_set.cpp 2013-06-11 16:49:27 +0000
4140@@ -16,11 +16,11 @@
4141 #include "stdafx.h"
4142
4143 #include <zorba/config.h>
4144+#include <zorba/internal/cxx_util.h>
4145
4146 #include "context/static_context.h"
4147 #include "context/uri_resolver.h"
4148 #include "util/ascii_util.h"
4149-#include "util/cxx_util.h"
4150 #include "util/mmap_file.h"
4151 #include "util/stl_util.h"
4152 #include "util/uri_util.h"
4153
4154=== modified file 'src/runtime/full_text/ft_token_matcher.cpp'
4155--- src/runtime/full_text/ft_token_matcher.cpp 2013-02-07 17:24:36 +0000
4156+++ src/runtime/full_text/ft_token_matcher.cpp 2013-06-11 16:49:27 +0000
4157@@ -17,14 +17,14 @@
4158
4159 #include <cctype>
4160
4161+#include <zorba/internal/cxx_util.h>
4162+
4163 #include "compiler/expression/ftnode.h"
4164 #include "diagnostics/assert.h"
4165 #include "store/api/store.h"
4166-#include "util/cxx_util.h"
4167+#include "system/globalenv.h"
4168 #include "util/stl_util.h"
4169
4170-#include "system/globalenv.h"
4171-
4172 #include "ft_stop_words_set.h"
4173 #include "ft_token_matcher.h"
4174 #include "ft_util.h"
4175
4176=== modified file 'src/runtime/full_text/ft_token_seq_iterator.cpp'
4177--- src/runtime/full_text/ft_token_seq_iterator.cpp 2013-02-07 17:24:36 +0000
4178+++ src/runtime/full_text/ft_token_seq_iterator.cpp 2013-06-11 16:49:27 +0000
4179@@ -15,7 +15,8 @@
4180 */
4181 #include "stdafx.h"
4182
4183-#include "util/cxx_util.h"
4184+#include <zorba/internal/cxx_util.h>
4185+
4186 #include "diagnostics/assert.h"
4187
4188 #include "ft_token_seq_iterator.h"
4189
4190=== modified file 'src/runtime/full_text/ft_util.h'
4191--- src/runtime/full_text/ft_util.h 2013-02-07 17:24:36 +0000
4192+++ src/runtime/full_text/ft_util.h 2013-06-11 16:49:27 +0000
4193@@ -17,12 +17,12 @@
4194 #ifndef ZORBA_FULL_TEXT_UTIL_H
4195 #define ZORBA_FULL_TEXT_UTIL_H
4196
4197+#include <zorba/internal/cxx_util.h>
4198 #include <zorba/item.h>
4199 #include <zorba/locale.h>
4200
4201 #include "compiler/expression/ftnode.h"
4202 #include "store/api/item.h"
4203-#include "util/cxx_util.h"
4204 #include "zorbatypes/schema_types.h"
4205
4206 #include "ft_match.h"
4207
4208=== modified file 'src/runtime/full_text/ftcontains_visitor.cpp'
4209--- src/runtime/full_text/ftcontains_visitor.cpp 2013-05-08 20:14:47 +0000
4210+++ src/runtime/full_text/ftcontains_visitor.cpp 2013-06-11 16:49:27 +0000
4211@@ -19,13 +19,14 @@
4212 #include <limits>
4213 #include <memory>
4214
4215+#include <zorba/internal/cxx_util.h>
4216+
4217 #include "compiler/expression/ft_expr.h"
4218 #include "compiler/expression/ftnode.h"
4219 #include "compiler/parser/query_loc.h"
4220 #include "diagnostics/xquery_diagnostics.h"
4221 #include "store/api/store.h"
4222 #include "system/globalenv.h"
4223-#include "util/cxx_util.h"
4224 #include "util/indent.h"
4225 #include "util/stl_util.h"
4226 #include "zorbatypes/integer.h"
4227
4228=== modified file 'src/runtime/full_text/icu_tokenizer.cpp'
4229--- src/runtime/full_text/icu_tokenizer.cpp 2013-02-07 17:24:36 +0000
4230+++ src/runtime/full_text/icu_tokenizer.cpp 2013-06-11 16:49:27 +0000
4231@@ -25,6 +25,7 @@
4232 #endif /* DEBUG_TOKENIZER */
4233
4234 #include <zorba/diagnostic_list.h>
4235+#include <zorba/internal/cxx_util.h>
4236 #include <zorba/internal/unique_ptr.h>
4237
4238 #include "diagnostics/assert.h"
4239@@ -32,7 +33,6 @@
4240 #include "diagnostics/xquery_exception.h"
4241 #include "diagnostics/zorba_exception.h"
4242 #include "util/ascii_util.h"
4243-#include "util/cxx_util.h"
4244 #include "util/stl_util.h"
4245 #include "util/unicode_util.h"
4246 #include "util/utf8_util.h"
4247
4248=== modified file 'src/runtime/full_text/icu_tokenizer.h'
4249--- src/runtime/full_text/icu_tokenizer.h 2013-02-07 17:24:36 +0000
4250+++ src/runtime/full_text/icu_tokenizer.h 2013-06-11 16:49:27 +0000
4251@@ -19,12 +19,11 @@
4252
4253 #include <unicode/rbbi.h> /* for RuleBasedBreakIterator */
4254
4255+#include <zorba/internal/cxx_util.h>
4256 #include <zorba/internal/unique_ptr.h>
4257 #include <zorba/locale.h>
4258 #include <zorba/tokenizer.h>
4259
4260-#include "util/cxx_util.h"
4261-
4262 namespace zorba {
4263
4264 ///////////////////////////////////////////////////////////////////////////////
4265
4266=== modified file 'src/runtime/full_text/stemmer.cpp'
4267--- src/runtime/full_text/stemmer.cpp 2013-02-07 17:24:36 +0000
4268+++ src/runtime/full_text/stemmer.cpp 2013-06-11 16:49:27 +0000
4269@@ -15,7 +15,8 @@
4270 */
4271 #include "stdafx.h"
4272
4273-#include "util/cxx_util.h"
4274+#include <zorba/internal/cxx_util.h>
4275+
4276 #include "zorbautils/locale.h"
4277 #include "zorbautils/mutex.h"
4278
4279
4280=== modified file 'src/runtime/full_text/stemmer/sb_stemmer.cpp'
4281--- src/runtime/full_text/stemmer/sb_stemmer.cpp 2013-02-07 17:24:36 +0000
4282+++ src/runtime/full_text/stemmer/sb_stemmer.cpp 2013-06-11 16:49:27 +0000
4283@@ -15,7 +15,8 @@
4284 */
4285 #include "stdafx.h"
4286
4287-#include "util/cxx_util.h"
4288+#include <zorba/internal/cxx_util.h>
4289+
4290 #include "zorbautils/fatal.h"
4291 #include "zorbautils/locale.h"
4292
4293
4294=== modified file 'src/runtime/full_text/thesauri/encoded_list.h'
4295--- src/runtime/full_text/thesauri/encoded_list.h 2013-02-07 17:24:36 +0000
4296+++ src/runtime/full_text/thesauri/encoded_list.h 2013-06-11 16:49:27 +0000
4297@@ -20,7 +20,7 @@
4298 #include <cstddef> /* for size_t */
4299 #include <iterator>
4300
4301-#include "util/cxx_util.h"
4302+#include <zorba/internal/cxx_util.h>
4303
4304 namespace zorba {
4305
4306
4307=== modified file 'src/runtime/full_text/thesauri/wn_thesaurus.cpp'
4308--- src/runtime/full_text/thesauri/wn_thesaurus.cpp 2013-02-07 17:24:36 +0000
4309+++ src/runtime/full_text/thesauri/wn_thesaurus.cpp 2013-06-11 16:49:27 +0000
4310@@ -21,24 +21,21 @@
4311 #include <cstring> /* for strcmp(3) */
4312 #include <limits>
4313
4314-#include <zorba/util/path.h>
4315-
4316-#include <context/static_context.h>
4317-
4318-#include "util/cxx_util.h"
4319+#include <zorba/internal/cxx_util.h>
4320+
4321+#include "context/static_context.h"
4322+#include "diagnostics/assert.h"
4323+#include "diagnostics/dict.h"
4324+#include "diagnostics/xquery_diagnostics.h"
4325+#include "system/globalenv.h"
4326 #include "util/fs_util.h"
4327 #include "util/less.h"
4328 #if DEBUG_FT_THESAURUS
4329-#include "util/oseparator.h"
4330+# include "util/oseparator.h"
4331 #endif
4332 #include "util/utf8_util.h"
4333-#include "diagnostics/assert.h"
4334-#include "diagnostics/dict.h"
4335-#include "diagnostics/xquery_diagnostics.h"
4336 #include "zorbautils/locale.h"
4337
4338-#include "system/globalenv.h"
4339-
4340 #include "decode_base128.h"
4341 #include "wn_db_segment.h"
4342 #include "wn_synset.h"
4343
4344=== modified file 'src/runtime/full_text/thesaurus.cpp'
4345--- src/runtime/full_text/thesaurus.cpp 2013-02-07 17:24:36 +0000
4346+++ src/runtime/full_text/thesaurus.cpp 2013-06-11 16:49:27 +0000
4347@@ -18,15 +18,16 @@
4348 #include <map>
4349
4350 #include <zorba/config.h>
4351+#include <zorba/internal/cxx_util.h>
4352
4353-#include <context/static_context.h>
4354-#include <diagnostics/dict.h>
4355-#include <diagnostics/xquery_diagnostics.h>
4356-#include <util/cxx_util.h>
4357-#include <util/fs_util.h>
4358-#include <util/less.h>
4359-#include <util/string_util.h>
4360-#include <util/uri_util.h>
4361+#include "context/default_url_resolvers.h"
4362+#include "context/static_context.h"
4363+#include "diagnostics/dict.h"
4364+#include "diagnostics/xquery_diagnostics.h"
4365+#include "util/fs_util.h"
4366+#include "util/less.h"
4367+#include "util/string_util.h"
4368+#include "util/uri_util.h"
4369
4370 #include "thesaurus.h"
4371 #ifdef ZORBA_WITH_FILE_ACCESS
4372@@ -35,8 +36,6 @@
4373 #endif
4374 #include "thesauri/xqftts_thesaurus.h"
4375
4376-#include "context/default_url_resolvers.h"
4377-
4378 using namespace std;
4379 using namespace zorba::locale;
4380
4381@@ -112,8 +111,13 @@
4382 //
4383 zstring t_uri( url_copy );
4384 t_uri.replace( 0, 6, "file" ); // xqftts -> file
4385- zstring const t_path( fs::get_normalized_path( t_uri ) );
4386- return new xqftts::provider( t_path );
4387+ try {
4388+ zstring const t_path( fs::normalize_path( t_uri ) );
4389+ return new xqftts::provider( t_path );
4390+ }
4391+ catch ( invalid_argument const &e ) {
4392+ throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
4393+ }
4394 }
4395 # endif /* ZORBA_WITH_FILE_ACCESS */
4396 case thesaurus_impl::wordnet:
4397
4398=== modified file 'src/runtime/json/json_impl.cpp'
4399--- src/runtime/json/json_impl.cpp 2013-02-26 04:12:43 +0000
4400+++ src/runtime/json/json_impl.cpp 2013-06-11 16:49:27 +0000
4401@@ -19,13 +19,12 @@
4402 #include <sstream>
4403
4404 #include <zorba/diagnostic_list.h>
4405+#include <zorba/internal/cxx_util.h>
4406
4407 #include "runtime/json/json.h"
4408 #include "store/api/item_factory.h"
4409 #include "system/globalenv.h"
4410-
4411 #include "util/ascii_util.h"
4412-#include "util/cxx_util.h"
4413 #include "util/mem_streambuf.h"
4414 #include "util/stream_util.h"
4415
4416
4417=== modified file 'src/runtime/json/jsonml_array.cpp'
4418--- src/runtime/json/jsonml_array.cpp 2013-04-02 02:48:56 +0000
4419+++ src/runtime/json/jsonml_array.cpp 2013-06-11 16:49:27 +0000
4420@@ -18,13 +18,13 @@
4421 #include <sstream>
4422
4423 #include <zorba/diagnostic_list.h>
4424+#include <zorba/internal/cxx_util.h>
4425
4426 #include "runtime/json/json.h"
4427 #include "store/api/item_factory.h"
4428 #include "system/globalenv.h"
4429 #include "types/root_typemanager.h"
4430 #include "util/ascii_util.h"
4431-#include "util/cxx_util.h"
4432 #include "util/json_parser.h"
4433 #include "util/json_util.h"
4434 #include "util/mem_streambuf.h"
4435
4436=== modified file 'src/runtime/json/snelson.cpp'
4437--- src/runtime/json/snelson.cpp 2013-02-07 17:24:36 +0000
4438+++ src/runtime/json/snelson.cpp 2013-06-11 16:49:27 +0000
4439@@ -19,13 +19,13 @@
4440 #include <string>
4441
4442 #include <zorba/diagnostic_list.h>
4443+#include <zorba/internal/cxx_util.h>
4444
4445 #include "runtime/json/json.h"
4446 #include "store/api/item_factory.h"
4447 #include "system/globalenv.h"
4448 #include "types/root_typemanager.h"
4449 #include "util/ascii_util.h"
4450-#include "util/cxx_util.h"
4451 #include "util/indent.h"
4452 #include "util/json_parser.h"
4453 #include "util/json_util.h"
4454
4455=== modified file 'src/runtime/util/doc_uri_heuristics.cpp'
4456--- src/runtime/util/doc_uri_heuristics.cpp 2012-10-16 14:30:02 +0000
4457+++ src/runtime/util/doc_uri_heuristics.cpp 2013-06-11 16:49:27 +0000
4458@@ -47,24 +47,31 @@
4459 uri::get_scheme(aUri) == uri::unknown) &&
4460 uri::get_scheme(lBaseUri) == uri::file)
4461 {
4462- // Ok, we assume it's a filesystem path. First normalize it.
4463- zstring lNormalizedPath = fs::get_normalized_path(
4464- aUri,
4465- zstring(""));
4466- // QQQ For now, get_normalized_path() doesn't do what we
4467- // want when base URI represents a file. So, when the
4468- // normalized path is relative, we pretend it's a relative
4469- // URI and resolve it as such.
4470- if (fs::is_absolute(lNormalizedPath))
4471+ try
4472 {
4473- URI::encode_file_URI(lNormalizedPath, *aResult);
4474+ // Ok, we assume it's a filesystem path. First normalize it.
4475+ zstring lNormalizedPath = fs::normalize_path(
4476+ aUri,
4477+ zstring(""));
4478+ // QQQ For now, normalize_path() doesn't do what we
4479+ // want when base URI represents a file. So, when the
4480+ // normalized path is relative, we pretend it's a relative
4481+ // URI and resolve it as such.
4482+ if (fs::is_absolute(lNormalizedPath))
4483+ {
4484+ URI::encode_file_URI(lNormalizedPath, *aResult);
4485+ }
4486+ else
4487+ {
4488+ #ifdef WIN32
4489+ ascii::replace_all(lNormalizedPath, '\\', '/');
4490+ #endif
4491+ *aResult = aSctx->resolve_relative_uri(lNormalizedPath, true);
4492+ }
4493 }
4494- else
4495+ catch ( std::invalid_argument const &e )
4496 {
4497-#ifdef WIN32
4498- ascii::replace_all(lNormalizedPath, '\\', '/');
4499-#endif
4500- *aResult = aSctx->resolve_relative_uri(lNormalizedPath, true);
4501+ throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
4502 }
4503 }
4504 else
4505@@ -87,6 +94,5 @@
4506 }
4507 }
4508
4509-} /* namespace zorba */
4510+} // namespace zorba
4511 /* vim:set et sw=2 ts=2: */
4512-
4513
4514=== modified file 'src/store/naive/ft_token_store.h'
4515--- src/store/naive/ft_token_store.h 2013-02-07 17:24:36 +0000
4516+++ src/store/naive/ft_token_store.h 2013-06-11 16:49:27 +0000
4517@@ -21,7 +21,8 @@
4518 #include <utility> /* for pair */
4519 #include <vector>
4520
4521-#include "util/cxx_util.h"
4522+#include <zorba/internal/cxx_util.h>
4523+
4524 #include "zorbatypes/ft_token.h"
4525
4526 namespace zorba {
4527
4528=== modified file 'src/store/naive/naive_ft_token_iterator.cpp'
4529--- src/store/naive/naive_ft_token_iterator.cpp 2013-02-07 17:24:36 +0000
4530+++ src/store/naive/naive_ft_token_iterator.cpp 2013-06-11 16:49:27 +0000
4531@@ -15,8 +15,9 @@
4532 */
4533 #include "stdafx.h"
4534
4535+#include <zorba/internal/cxx_util.h>
4536+
4537 #include "diagnostics/assert.h"
4538-#include "util/cxx_util.h"
4539
4540 #include "naive_ft_token_iterator.h"
4541
4542
4543=== modified file 'src/store/naive/store.cpp'
4544--- src/store/naive/store.cpp 2013-03-20 18:39:54 +0000
4545+++ src/store/naive/store.cpp 2013-06-11 16:49:27 +0000
4546@@ -21,6 +21,8 @@
4547
4548 #include <libxml/parser.h>
4549
4550+#include <zorba/internal/cxx_util.h>
4551+
4552 #include "zorbautils/hashfun.h"
4553 #include "zorbautils/fatal.h"
4554 #include "zorbatypes/rchandle.h"
4555@@ -57,7 +59,6 @@
4556 #include "pul_primitive_factory.h"
4557 #include "tree_id_generator.h"
4558
4559-#include "util/cxx_util.h"
4560 #include "zorbautils/string_util.h"
4561
4562 #ifndef ZORBA_NO_FULL_TEXT
4563
4564=== modified file 'src/unit_tests/CMakeLists.txt'
4565--- src/unit_tests/CMakeLists.txt 2013-04-16 18:24:35 +0000
4566+++ src/unit_tests/CMakeLists.txt 2013-06-11 16:49:27 +0000
4567@@ -17,6 +17,7 @@
4568 test_ato_.cpp
4569 test_base64.cpp
4570 test_base64_streambuf.cpp
4571+ test_fs_util.cpp
4572 test_hashmaps.cpp
4573 test_hexbinary.cpp
4574 test_json_parser.cpp
4575@@ -26,16 +27,11 @@
4576 test_time.cpp
4577 test_time_parse.cpp
4578 test_uri.cpp
4579+ test_utf8_streambuf.cpp
4580 test_uuid.cpp
4581 unit_tests.cpp
4582- test_utf8_streambuf.cpp
4583 )
4584
4585-IF (ZORBA_WITH_FILE_ACCESS)
4586- LIST (APPEND UNIT_TEST_SRCS
4587- test_fs_iterator.cpp)
4588-ENDIF (ZORBA_WITH_FILE_ACCESS)
4589-
4590 IF (NOT ZORBA_NO_FULL_TEXT)
4591 LIST (APPEND UNIT_TEST_SRCS
4592 test_stemmer.cpp
4593
4594=== modified file 'src/unit_tests/test_ato_.cpp'
4595--- src/unit_tests/test_ato_.cpp 2013-05-03 23:19:41 +0000
4596+++ src/unit_tests/test_ato_.cpp 2013-06-11 16:49:27 +0000
4597@@ -19,7 +19,8 @@
4598 #include <stdexcept>
4599 #include <string>
4600
4601-#include "util/cxx_util.h"
4602+#include <zorba/internal/cxx_util.h>
4603+
4604 #include "util/string_util.h"
4605
4606 using namespace std;
4607
4608=== removed file 'src/unit_tests/test_fs_iterator.cpp'
4609--- src/unit_tests/test_fs_iterator.cpp 2012-04-22 15:49:55 +0000
4610+++ src/unit_tests/test_fs_iterator.cpp 1970-01-01 00:00:00 +0000
4611@@ -1,54 +0,0 @@
4612-/*
4613- * Copyright 2006-2010 The FLWOR Foundation.
4614- *
4615- * Licensed under the Apache License, Version 2.0 (the "License");
4616- * you may not use this file except in compliance with the License.
4617- * You may obtain a copy of the License at
4618- *
4619- * http://www.apache.org/licenses/LICENSE-2.0
4620- *
4621- * Unless required by applicable law or agreed to in writing, software
4622- * distributed under the License is distributed on an "AS IS" BASIS,
4623- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4624- * See the License for the specific language governing permissions and
4625- * limitations under the License.
4626- */
4627-
4628-#include "stdafx.h"
4629-
4630-#include <iostream>
4631-#include <zorba/zorba_exception.h>
4632-
4633-#include "util/fs_util.h"
4634-
4635-using namespace std;
4636-using namespace zorba;
4637-
4638-///////////////////////////////////////////////////////////////////////////////
4639-
4640-namespace zorba {
4641-namespace UnitTests {
4642-
4643-int test_fs_iterator( int argc, char *argv[] ) {
4644- int result = 0;
4645- try {
4646-#ifndef WIN32
4647- fs::iterator dir_iter( "/" );
4648-#else
4649- fs::iterator dir_iter( "C:\\" );
4650-#endif /* WIN32 */
4651- while ( dir_iter.next() )
4652- cout << dir_iter.entry_name() << " (" << dir_iter.entry_type() << ')' << endl;
4653- }
4654- catch ( ZorbaException const &e ) {
4655- cerr << e << endl;
4656- result = 2;
4657- }
4658-
4659- return result;
4660-}
4661-
4662-} // namespace UnitTests
4663-} // namespace zorba
4664-
4665-/* vim:set et sw=2 ts=2: */
4666
4667=== added file 'src/unit_tests/test_fs_util.cpp'
4668--- src/unit_tests/test_fs_util.cpp 1970-01-01 00:00:00 +0000
4669+++ src/unit_tests/test_fs_util.cpp 2013-06-11 16:49:27 +0000
4670@@ -0,0 +1,178 @@
4671+/*
4672+ * Copyright 2006-2008 The FLWOR Foundation.
4673+ *
4674+ * Licensed under the Apache License, Version 2.0 (the "License");
4675+ * you may not use this file except in compliance with the License.
4676+ * You may obtain a copy of the License at
4677+ *
4678+ * http://www.apache.org/licenses/LICENSE-2.0
4679+ *
4680+ * Unless required by applicable law or agreed to in writing, software
4681+ * distributed under the License is distributed on an "AS IS" BASIS,
4682+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4683+ * See the License for the specific language governing permissions and
4684+ * limitations under the License.
4685+ */
4686+
4687+#include "stdafx.h"
4688+
4689+#include <cstring>
4690+
4691+#include "util/fs_util.h"
4692+
4693+using namespace std;
4694+using namespace zorba;
4695+
4696+struct test {
4697+ char const *input;
4698+ char const *expected;
4699+};
4700+
4701+///////////////////////////////////////////////////////////////////////////////
4702+
4703+static int failures;
4704+
4705+static bool assert_true( int no, char const *expr, int line, bool result ) {
4706+ if ( !result ) {
4707+ cout << '#' << no << " FAILED, line " << line << ": " << expr << endl;
4708+ ++failures;
4709+ }
4710+ return result;
4711+}
4712+
4713+static void print_exception( int no, char const *expr, int line,
4714+ std::exception const &e ) {
4715+ assert_true( no, expr, line, false );
4716+ cout << "+ exception: " << e.what() << endl;
4717+}
4718+
4719+#define ASSERT_TRUE( NO, EXPR ) assert_true( NO, #EXPR, __LINE__, !!(EXPR) )
4720+
4721+#define ASSERT_NO_EXCEPTION( NO, EXPR ) \
4722+ try { EXPR; } \
4723+ catch ( exception const &e ) { print_exception( NO, #EXPR, __LINE__, e ); } \
4724+ catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
4725+
4726+#define ASSERT_EXCEPTION( NO, EXPR, EXCEPTION ) \
4727+ try { EXPR; assert_true( NO, #EXPR, __LINE__, false ); } \
4728+ catch ( EXCEPTION const& ) { } \
4729+ catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
4730+
4731+///////////////////////////////////////////////////////////////////////////////}
4732+
4733+void test_base_name( int no, char const *path, char const *expected ) {
4734+ ASSERT_TRUE( no, ::strcmp( fs::base_name( path ), expected ) == 0 );
4735+}
4736+
4737+void test_base_name( int no, string const &path, string const &expected ) {
4738+ ASSERT_TRUE( no, fs::base_name( path ) == expected );
4739+}
4740+
4741+void test_dir_name( int no, char const *path, char const *expected ) {
4742+ ASSERT_TRUE( no, fs::dir_name( path ) == expected );
4743+}
4744+
4745+void test_dir_name( int no, string const &path, string const &expected ) {
4746+ ASSERT_TRUE( no, fs::dir_name( path ) == expected );
4747+}
4748+
4749+void test_normalize_path( int no, char const *path, char const *expected ) {
4750+ ASSERT_TRUE( no, fs::normalize_path( path ) == expected );
4751+}
4752+
4753+///////////////////////////////////////////////////////////////////////////////}
4754+
4755+static test const base_name_tests[] = {
4756+#ifndef WIN32
4757+ /* 0 */ { "/a/b", "b" },
4758+ /* 1 */ { "/a" , "a" },
4759+ /* 2 */ { "/" , "/" },
4760+ /* 3 */ { "a/b" , "b" },
4761+ /* 4 */ { "a" , "a" },
4762+#else
4763+ /* 0 */ { "C:\\a\\b", "b" },
4764+ /* 1 */ { "C:\\a" , "a" },
4765+ /* 2 */ { "C:\\" , "C:\\" },
4766+ /* 3 */ { "a\\b" , "b" },
4767+ /* 4 */ { "a" , "a" },
4768+#endif /* WIN32 */
4769+ { 0, 0 }
4770+};
4771+
4772+static test const dir_name_tests[] = {
4773+#ifndef WIN32
4774+ /* 0 */ { "/a/b", "/a" },
4775+ /* 1 */ { "/a" , "/" },
4776+ /* 2 */ { "/" , "/" },
4777+ /* 3 */ { "a/b" , "a" },
4778+ /* 4 */ { "a" , "." },
4779+#else
4780+ /* 0 */ { "C:\\a\\b", "C:\\a" },
4781+ /* 1 */ { "C:\\a" , "C:\\" },
4782+ /* 2 */ { "C:\\" , "C:\\" },
4783+ /* 3 */ { "a\\b" , "a" },
4784+ /* 4 */ { "a" , "." },
4785+#endif /* WIN32 */
4786+ { 0, 0 }
4787+};
4788+
4789+static test normalize_path_tests[] = {
4790+#ifndef WIN32
4791+ /* 0 */ { "/a//b" , "/a/b" },
4792+ /* 1 */ { "/a///b" , "/a/b" },
4793+ /* 2 */ { "/a/./b" , "/a/b" },
4794+ /* 3 */ { "/a/././b" , "/a/b" },
4795+ /* 4 */ { "/a/b/." , "/a/b" },
4796+ /* 5 */ { "/a/../b" , "/b" },
4797+ /* 6 */ { "/a/b/../../c" , "/c" },
4798+ /* 7 */ { "/a/b/../c/../d" , "/a/d" },
4799+ /* 8 */ { "/a/b/.." , "/a" },
4800+ /* 9 */ { "file:///a/b" , "/a/b" },
4801+ /* 10 */ { "file://localhost/a/b" , "/a/b" },
4802+ /* 11 */ { "\\a\\b" , "/a/b" },
4803+#else
4804+ /* 0 */ { "C:\\a\\\\b" , "C:\\a\\b" },
4805+ /* 1 */ { "C:\\a\\\\\\b" , "C:\\a\\b" },
4806+ /* 2 */ { "C:\\a\\.\\b" , "C:\\a\\b" },
4807+ /* 3 */ { "C:\\a\\.\\.\\b" , "C:\\a\\b" },
4808+ /* 4 */ { "C:\\a\\b\\." , "C:\\a\\b" },
4809+ /* 5 */ { "C:\\a\\..\\b" , "C:\\b" },
4810+ /* 6 */ { "C:\\a\\b\\..\\..\\c" , "C:\\c" },
4811+ /* 7 */ { "C:\\a\\b\\..\\c\\..\\d" , "C:\\a\\d" },
4812+ /* 8 */ { "C:\\a\\b\\.." , "C:\\a" },
4813+ /* 9 */ { "file:///C%3A/a/b" , "C:\\a\\b" },
4814+ /* 10 */ { "file://localhost/C%3A/a/b" , "C:\\a\\b" },
4815+ /* 11 */ { "C:/a/b" , "C:\\a\\b" },
4816+#endif /* WIN32 */
4817+ { 0, 0 }
4818+};
4819+
4820+namespace zorba {
4821+namespace UnitTests {
4822+
4823+int test_fs_util( int, char*[] ) {
4824+ int test_no = 0;
4825+
4826+ for ( test const *t = base_name_tests; t->input; ++t, ++test_no ) {
4827+ test_base_name( test_no, t->input, t->expected );
4828+ test_base_name( test_no, string( t->input ), string( t->expected ) );
4829+ }
4830+
4831+ test_no = 0;
4832+ for ( test const *t = dir_name_tests; t->input; ++t, ++test_no ) {
4833+ test_dir_name( test_no, t->input, t->expected );
4834+ test_dir_name( test_no, string( t->input ), string( t->expected ) );
4835+ }
4836+
4837+ test_no = 0;
4838+ for ( test const *t = normalize_path_tests; t->input; ++t, ++test_no )
4839+ test_normalize_path( test_no, t->input, t->expected );
4840+
4841+ cout << failures << " test(s) failed\n";
4842+ return failures ? 1 : 0;
4843+}
4844+
4845+} // namespace UnitTests
4846+} // namespace zorba
4847+
4848+/* vim:set et sw=2 ts=2: */
4849
4850=== modified file 'src/unit_tests/test_mem_sizeof.cpp'
4851--- src/unit_tests/test_mem_sizeof.cpp 2013-04-17 18:37:33 +0000
4852+++ src/unit_tests/test_mem_sizeof.cpp 2013-06-11 16:49:27 +0000
4853@@ -18,7 +18,8 @@
4854 #include <iostream>
4855 #include <string>
4856
4857-#include "util/cxx_util.h"
4858+#include <zorba/internal/cxx_util.h>
4859+
4860 #include "util/mem_sizeof.h"
4861
4862 using namespace std;
4863
4864=== modified file 'src/unit_tests/test_string.cpp'
4865--- src/unit_tests/test_string.cpp 2013-05-08 01:05:04 +0000
4866+++ src/unit_tests/test_string.cpp 2013-06-11 16:49:27 +0000
4867@@ -403,9 +403,9 @@
4868 ascii::replace_all( s2, '/', '\\' );
4869 ASSERT_TRUE( s2 == t );
4870
4871- s1 = StringType ("\"");
4872- t = StringType("\\\"");
4873- ascii::replace_all( s1, "\"", "\\\"");
4874+ s1 = '"';
4875+ t = "\\\"";
4876+ ascii::replace_all( s1, "\"", "\\\"" );
4877 ASSERT_TRUE( s1 == t );
4878 }
4879
4880
4881=== modified file 'src/unit_tests/unit_test_list.h'
4882--- src/unit_tests/unit_test_list.h 2013-04-16 18:24:35 +0000
4883+++ src/unit_tests/unit_test_list.h 2013-06-11 16:49:27 +0000
4884@@ -31,6 +31,7 @@
4885 int test_ato_( int, char*[] );
4886 int test_base64( int, char*[] );
4887 int test_base64_streambuf( int, char*[] );
4888+ int test_fs_util( int, char*[] );
4889 int test_hashmaps( int argc, char* argv[] );
4890 int test_hexbinary( int argc, char* argv[] );
4891
4892@@ -45,10 +46,6 @@
4893 int test_time( int, char*[] );
4894 int test_time_parse( int, char*[] );
4895
4896-#ifdef ZORBA_WITH_FILE_ACCESS
4897- int test_fs_iterator( int, char*[] );
4898-#endif /* ZORBA_WITH_FILE_ACCESS */
4899-
4900 #ifndef ZORBA_NO_FULL_TEXT
4901 int test_stemmer( int, char*[] );
4902 int test_thesaurus( int, char*[] );
4903
4904=== modified file 'src/unit_tests/unit_tests.cpp'
4905--- src/unit_tests/unit_tests.cpp 2013-04-16 18:24:35 +0000
4906+++ src/unit_tests/unit_tests.cpp 2013-06-11 16:49:27 +0000
4907@@ -40,11 +40,7 @@
4908 libunittests["ato"] = test_ato_;
4909 libunittests["base64"] = test_base64;
4910 libunittests["base64_streambuf"] = test_base64_streambuf;
4911-
4912-#ifdef ZORBA_WITH_FILE_ACCESS
4913- libunittests["fs_iterator"] = test_fs_iterator;
4914-#endif /* ZORBA_WITH_FILE_ACCESS */
4915-
4916+ libunittests["fs_util"] = test_fs_util;
4917 libunittests["hashmaps"] = test_hashmaps;
4918 libunittests["hexbinary"] = test_hexbinary;
4919
4920
4921=== modified file 'src/util/CMakeLists.txt'
4922--- src/util/CMakeLists.txt 2013-04-12 04:34:41 +0000
4923+++ src/util/CMakeLists.txt 2013-06-11 16:49:27 +0000
4924@@ -17,7 +17,6 @@
4925 base64_util.cpp
4926 dynamic_bitset.cpp
4927 error_util.cpp
4928- file.cpp
4929 fs_util.cpp
4930 hexbinary_util.cpp
4931 indent.cpp
4932
4933=== modified file 'src/util/base64_util.h'
4934--- src/util/base64_util.h 2013-05-09 00:48:27 +0000
4935+++ src/util/base64_util.h 2013-06-11 16:49:27 +0000
4936@@ -25,8 +25,8 @@
4937 #include <vector>
4938
4939 // Zorba
4940+#include <zorba/internal/cxx_util.h>
4941 #include <zorba/internal/ztd.h>
4942-#include "cxx_util.h"
4943 #include "stream_util.h"
4944
4945 namespace zorba {
4946
4947=== modified file 'src/util/cxx_util.cpp'
4948--- src/util/cxx_util.cpp 2013-01-15 19:16:16 +0000
4949+++ src/util/cxx_util.cpp 2013-06-11 16:49:27 +0000
4950@@ -20,9 +20,9 @@
4951
4952 #ifndef ZORBA_CXX_NULLPTR
4953
4954-#include "cxx_util.h"
4955+#include <zorba/internal/cxx_util.h>
4956
4957-zorba::nullptr_type const zorba_nullptr = { };
4958+zorba::internal::nullptr_type const zorba_nullptr = { };
4959
4960 #endif /* ZORBA_CXX_NULLPTR */
4961
4962
4963=== modified file 'src/util/error_util.cpp'
4964--- src/util/error_util.cpp 2013-02-07 17:24:36 +0000
4965+++ src/util/error_util.cpp 2013-06-11 16:49:27 +0000
4966@@ -17,7 +17,6 @@
4967
4968 #include <sstream>
4969
4970-# include <cstring>
4971 #ifndef WIN32
4972 # include <cstdio>
4973 #else
4974@@ -25,11 +24,11 @@
4975 #endif /* WIN32 */
4976
4977 #include <zorba/internal/unique_ptr.h>
4978+#include <zorba/util/error_util.h>
4979
4980 #include "diagnostics/dict.h"
4981 #include "diagnostics/diagnostic.h"
4982
4983-#include "error_util.h"
4984 #include "stl_util.h"
4985
4986 namespace zorba {
4987@@ -39,12 +38,8 @@
4988
4989 ////////// exception //////////////////////////////////////////////////////////
4990
4991-exception::~exception() throw() {
4992- // out-of-line since it's virtual
4993-}
4994-
4995-string exception::make_what( char const *function, char const *path,
4996- char const *err_string ) {
4997+static string make_what( char const *function, char const *path,
4998+ char const *err_string ) {
4999 ostringstream oss;
5000 if ( path && *path )
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches