Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: 11243
Merged at revision: 11508
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 970 lines (+305/-240)
25 files modified
ChangeLog (+1/-0)
modules/org/expath/ns/file.xq (+6/-71)
modules/org/expath/ns/file.xq.src/file.cpp (+94/-53)
modules/org/expath/ns/file.xq.src/file.h (+32/-0)
modules/org/expath/ns/file.xq.src/file_function.cpp (+39/-38)
modules/org/expath/ns/file.xq.src/file_function.h (+6/-1)
modules/org/expath/ns/file.xq.src/file_module.cpp (+13/-9)
src/util/time_util.h (+1/-1)
test/rbkt/ExpQueryResults/zorba/file/dirname_basename-00.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/file/dirname_basename-01.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/file/dirname_basename-02.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/file/dirname_basename-03.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/file/dirname_basename-04.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/file/dirname_basename-05.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/file/dirname_basename-06.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/file/dirname_basename.xml.res (+0/-1)
test/rbkt/Queries/zorba/file/dirname_basename-00.xq (+16/-0)
test/rbkt/Queries/zorba/file/dirname_basename-01.xq (+16/-0)
test/rbkt/Queries/zorba/file/dirname_basename-02.xq (+16/-0)
test/rbkt/Queries/zorba/file/dirname_basename-03.xq (+16/-0)
test/rbkt/Queries/zorba/file/dirname_basename-04.xq (+16/-0)
test/rbkt/Queries/zorba/file/dirname_basename-05.xq (+10/-0)
test/rbkt/Queries/zorba/file/dirname_basename-06.xq (+16/-0)
test/rbkt/Queries/zorba/file/dirname_basename.spec (+0/-2)
test/rbkt/Queries/zorba/file/dirname_basename.xq (+0/-64)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+168983@code.launchpad.net

Commit message

Made base-name/dir-name "external," hence implemented in C++ rather than XQuery. The C++ implementation is trivial and the XQuery implementation was dozens of lines. The XQuery implementation hangs (after fs_util merge) for some bizarre reason and it's not worth debugging when the C++ implementation is much better.

Description of the change

Made base-name/dir-name "external," hence implemented in C++ rather than XQuery. The C++ implementation is trivial and the XQuery implementation was dozens of lines. The XQuery implementation hangs (after fs_util merge) for some bizarre reason and it's not worth debugging when the C++ implementation is much better.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~paul-lucas/zorba/pjl-misc 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 pjl-misc-2013-06-12T15-55-56.425Z is finished. The
  final status was:

  1 tests did not succeed - changes not commited.

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

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2013-06-12T23-59-50.355Z is finished. The final status was:

All tests succeeded!

Revision history for this message
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.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2013-06-13T00-48-45.492Z 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 23:35:24 +0000
3+++ ChangeLog 2013-06-12 23:56:32 +0000
4@@ -22,6 +22,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 #1190261 (relative paths bug in file module)
9 * Fixed bug #1180220 (Consolidate redundant path/file public APIs)
10 * Fixed bug #1103115 (Timezone units as hours are wrong)
11 * Fixed implementation of fn:deep-equal according to latest W3C spec.
12
13=== modified file 'modules/org/expath/ns/file.xq'
14--- modules/org/expath/ns/file.xq 2013-06-06 20:56:08 +0000
15+++ modules/org/expath/ns/file.xq 2013-06-12 23:56:32 +0000
16@@ -751,29 +751,7 @@
17 : @param $path A file path/URI.
18 : @return The base name of this file.
19 :)
20-declare function file:base-name($path as xs:string) as xs:string
21-{
22- let $delim := file:directory-separator()
23- let $escapedDelim :=
24- if ($delim eq "/") then
25- $delim
26- else
27- fn:concat("\", $delim)
28- let $normalized-file :=
29- let $n := file:prepare-for-dirname-and-base-name($path)
30- return if ($delim eq "\" and fn:matches($n, "^[a-zA-Z]:$")) then
31- fn:concat($n, "\")
32- else $n
33- return
34- if (fn:matches($path, fn:concat("^", $escapedDelim, "+$"))) then
35- ""
36- else if ($delim eq "\" and fn:matches($path, "^[a-zA-Z]:\\?$")) then
37- ""
38- else if ($path eq "") then
39- "."
40- else
41- fn:replace($normalized-file, fn:concat("^.*", $escapedDelim), "")
42-};
43+declare function file:base-name($path as xs:string) as xs:string external;
44
45 (:~
46 : Returns the last component from the <pre>$path</pre>, deleting any
47@@ -790,12 +768,13 @@
48 : @param $suffix A suffix which should get deleted from the result.
49 : @return The base-name of $path with a deleted $suffix.
50 :)
51-declare function file:base-name($path as xs:string, $suffix as xs:string) as xs:string
52+declare function file:base-name($path as xs:string, $suffix as xs:string)
53+ as xs:string
54 {
55 let $res := file:base-name($path)
56 return
57 if (fn:ends-with($res, $suffix) and $res ne ".") then
58- fn:substring($res, 1, fn:string-length($suffix))
59+ fn:substring($res, 1, fn:string-length($res) - fn:string-length($suffix))
60 else
61 $res
62 };
63@@ -812,50 +791,6 @@
64 : @param $path The filename, of which the dirname should be get.
65 : @return The name of the directory the file is in.
66 :)
67-declare function file:dir-name($path as xs:string) as xs:string
68-{
69- let $delim := file:directory-separator()
70- let $escapedDelim :=
71- if ($delim eq "/") then
72- $delim
73- else
74- fn:concat("\", $delim)
75- let $normalized-file := file:prepare-for-dirname-and-base-name($path)
76- return
77- if (fn:matches($path, fn:concat("^", $escapedDelim, "+$"))) then
78- $delim
79- else if ($normalized-file eq $delim) then
80- $delim
81- else if ($delim eq "\" and fn:matches($path, "^[a-zA-Z]:\\$")) then
82- $path
83- else if ($delim eq "\" and fn:matches($normalized-file, "^[a-zA-Z]:$")) then
84- fn:concat($normalized-file, '\')
85- else if ($path eq "") then
86- "."
87- else if (fn:matches($normalized-file, $escapedDelim)) then
88- fn:replace($normalized-file, fn:concat("^(.*)", $escapedDelim, ".*"), "$1")
89- else
90- "."
91-};
92+declare function file:dir-name($path as xs:string) as xs:string external;
93
94-(:~
95- : This is a helper function used by dirname and base-name. This function takes a path as
96- : input and normalizes it according to the rules states in dirname/base-name documentation
97- : and normalizes it to a system specific path.
98- :)
99-declare %private function file:prepare-for-dirname-and-base-name($path as xs:string) as xs:string
100-{
101- let $delim := file:directory-separator()
102- let $escapedDelim :=
103- if ($delim eq "/") then
104- $delim
105- else
106- fn:concat("\", $delim)
107- let $normalize-path := file:path-to-native($path)
108- let $normalized :=
109- if ($normalize-path eq $delim) then
110- $normalize-path
111- else
112- fn:replace($normalize-path, fn:concat($escapedDelim, "+$"), "")
113- return $normalized
114-};
115+(: vim:set et sw=2 ts=2: :)
116
117=== modified file 'modules/org/expath/ns/file.xq.src/file.cpp'
118--- modules/org/expath/ns/file.xq.src/file.cpp 2013-06-04 05:33:22 +0000
119+++ modules/org/expath/ns/file.xq.src/file.cpp 2013-06-12 23:56:32 +0000
120@@ -41,6 +41,27 @@
121
122 //*****************************************************************************
123
124+BaseNameFunction::BaseNameFunction(const FileModule* aModule)
125+ : FileFunction(aModule)
126+{
127+}
128+
129+ItemSequence_t
130+BaseNameFunction::evaluate(
131+ ExternalFunction::Arguments_t const &args,
132+ StaticContext const*,
133+ DynamicContext const* ) const
134+{
135+ String path( getStringArg( args, 0 ) );
136+ while ( path.size() > 1 && path[ path.size() - 1 ] == fs::dir_separator )
137+ path.erase( path.size() - 1 );
138+ String const base_name( fs::base_name( path ) );
139+ Item item( theModule->getItemFactory()->createString( base_name ) );
140+ return ItemSequence_t( new SingletonItemSequence( item ) );
141+}
142+
143+//*****************************************************************************
144+
145 CreateDirectoryFunction::CreateDirectoryFunction(const FileModule* aModule)
146 : FileFunction(aModule)
147 {
148@@ -48,11 +69,11 @@
149
150 ItemSequence_t
151 CreateDirectoryFunction::evaluate(
152- ExternalFunction::Arguments_t const &aArgs,
153+ ExternalFunction::Arguments_t const &args,
154 StaticContext const*,
155 DynamicContext const* ) const
156 {
157- String const path( getFilePathString( aArgs, 0 ) );
158+ String const path( getPathArg( args, 0 ) );
159
160 if ( fs::get_type( path ) )
161 raiseFileError( "FOFL0002", "file already exists", path );
162@@ -76,11 +97,11 @@
163
164 ItemSequence_t
165 DeleteFileImplFunction::evaluate(
166- ExternalFunction::Arguments_t const &aArgs,
167+ ExternalFunction::Arguments_t const &args,
168 StaticContext const*,
169 DynamicContext const* ) const
170 {
171- String const path( getFilePathString( aArgs, 0 ) );
172+ String const path( getPathArg( args, 0 ) );
173
174 if ( !fs::get_type( path, false ) )
175 raiseFileError( "FOFL0001", "file not found", path );
176@@ -97,6 +118,27 @@
177
178 //*****************************************************************************
179
180+DirNameFunction::DirNameFunction(const FileModule* aModule)
181+ : FileFunction(aModule)
182+{
183+}
184+
185+ItemSequence_t
186+DirNameFunction::evaluate(
187+ ExternalFunction::Arguments_t const &args,
188+ StaticContext const*,
189+ DynamicContext const* ) const
190+{
191+ String path( getStringArg( args, 0 ) );
192+ while ( path.size() > 1 && path[ path.size() - 1 ] == fs::dir_separator )
193+ path.erase( path.size() - 1 );
194+ String const dir_name( fs::dir_name( path ) );
195+ Item item( theModule->getItemFactory()->createString( dir_name ) );
196+ return ItemSequence_t( new SingletonItemSequence( item ) );
197+}
198+
199+//*****************************************************************************
200+
201 ReadBinaryFunction::ReadBinaryFunction( FileModule const *aModule ) :
202 FileFunction( aModule )
203 {
204@@ -104,11 +146,11 @@
205
206 ItemSequence_t
207 ReadBinaryFunction::evaluate(
208- ExternalFunction::Arguments_t const &aArgs,
209+ ExternalFunction::Arguments_t const &args,
210 StaticContext const*,
211 DynamicContext const* ) const
212 {
213- String const path( getFilePathString( aArgs, 0 ) );
214+ String const path( getPathArg( args, 0 ) );
215
216 fs::type const fs_type = fs::get_type( path );
217 if ( !fs_type )
218@@ -140,11 +182,11 @@
219
220 ItemSequence_t
221 ReadTextFunction::evaluate(
222- ExternalFunction::Arguments_t const &aArgs,
223+ ExternalFunction::Arguments_t const &args,
224 StaticContext const*,
225 DynamicContext const* ) const
226 {
227- String const path( getFilePathString( aArgs, 0 ) );
228+ String const path( getPathArg( args, 0 ) );
229 String lEncoding( "UTF-8" );
230
231 fs::type const fs_type = fs::get_type( path );
232@@ -153,8 +195,8 @@
233 if ( fs_type != fs::file )
234 raiseFileError( "FOFL0004", "not a plain file", path );
235
236- if ( aArgs.size() == 2 )
237- lEncoding = getEncodingArg( aArgs, 1 );
238+ if ( args.size() == 2 )
239+ lEncoding = getEncodingArg( args, 1 );
240
241 zorba::Item lResult;
242
243@@ -188,12 +230,12 @@
244
245 ItemSequence_t
246 ReadTextLinesFunction::evaluate(
247- ExternalFunction::Arguments_t const &aArgs,
248+ ExternalFunction::Arguments_t const &args,
249 StaticContext const*,
250 DynamicContext const* ) const
251 {
252- String const path( getFilePathString( aArgs, 0 ) );
253- String const lEncoding( getEncodingArg( aArgs, 1 ) );
254+ String const path( getPathArg( args, 0 ) );
255+ String const lEncoding( getEncodingArg( args, 1 ) );
256
257 fs::type const fs_type = fs::get_type( path );
258 if ( !fs_type )
259@@ -293,12 +335,12 @@
260
261 ItemSequence_t
262 ExistsFunction::evaluate(
263- ExternalFunction::Arguments_t const &aArgs,
264+ ExternalFunction::Arguments_t const &args,
265 StaticContext const*,
266 DynamicContext const* ) const
267 {
268- String const path = getFilePathString( aArgs, 0 );
269- bool const follow_symlink = getItem( aArgs, 1 ).getBooleanValue();
270+ String const path = getPathArg( args, 0 );
271+ bool const follow_symlink = getItem( args, 1 ).getBooleanValue();
272 bool const exists = !!fs::get_type( path, follow_symlink );
273 return ItemSequence_t(
274 new SingletonItemSequence(
275@@ -316,11 +358,11 @@
276
277 ItemSequence_t
278 IsDirectoryFunction::evaluate(
279- ExternalFunction::Arguments_t const &aArgs,
280+ ExternalFunction::Arguments_t const &args,
281 StaticContext const*,
282 DynamicContext const* ) const
283 {
284- String const path( getFilePathString( aArgs, 0 ) );
285+ String const path( getPathArg( args, 0 ) );
286 bool const is_directory = fs::get_type( path ) == fs::directory;
287 return ItemSequence_t(
288 new SingletonItemSequence(
289@@ -338,11 +380,11 @@
290
291 ItemSequence_t
292 IsFileFunction::evaluate(
293- ExternalFunction::Arguments_t const &aArgs,
294+ ExternalFunction::Arguments_t const &args,
295 StaticContext const*,
296 DynamicContext const* ) const
297 {
298- String const path( getFilePathString( aArgs, 0 ) );
299+ String const path( getPathArg( args, 0 ) );
300 bool const is_file = fs::get_type( path ) == fs::file;
301 return ItemSequence_t(
302 new SingletonItemSequence(
303@@ -360,11 +402,11 @@
304
305 ItemSequence_t
306 IsSymlinkFunction::evaluate(
307- ExternalFunction::Arguments_t const &aArgs,
308+ ExternalFunction::Arguments_t const &args,
309 StaticContext const*,
310 DynamicContext const* ) const
311 {
312- String const path( getFilePathString( aArgs, 0 ) );
313+ String const path( getPathArg( args, 0 ) );
314 bool const is_symlink = fs::get_type( path, false ) == fs::link;
315 return ItemSequence_t(
316 new SingletonItemSequence(
317@@ -382,12 +424,12 @@
318
319 ItemSequence_t
320 CopyFileImplFunction::evaluate(
321- ExternalFunction::Arguments_t const &aArgs,
322+ ExternalFunction::Arguments_t const &args,
323 StaticContext const*,
324 DynamicContext const* ) const
325 {
326- String const src_path( getFilePathString( aArgs, 0 ) );
327- String dst_path( getFilePathString( aArgs, 1 ) );
328+ String const src_path( getPathArg( args, 0 ) );
329+ String dst_path( getPathArg( args, 1 ) );
330
331 fs::type const src_type = fs::get_type( src_path );
332 if ( !src_type )
333@@ -431,11 +473,11 @@
334
335 ItemSequence_t
336 ListFunction::evaluate(
337- ExternalFunction::Arguments_t const &aArgs,
338+ ExternalFunction::Arguments_t const &args,
339 StaticContext const*,
340 DynamicContext const* ) const
341 {
342- String const path( getFilePathString( aArgs, 0 ) );
343+ String const path( getPathArg( args, 0 ) );
344
345 if ( fs::get_type( path ) != fs::directory )
346 raiseFileError( "FOFL0003", "path is not a directory", path );
347@@ -494,8 +536,7 @@
348 {
349 if ( !theIterator.next() )
350 return false;
351-
352- String lUriStr( theIterator->name );
353+ String const lUriStr( theIterator->name );
354 lItem = theItemFactory->createString( lUriStr );
355 return true;
356 }
357@@ -509,11 +550,11 @@
358
359 ItemSequence_t
360 LastModifiedFunction::evaluate(
361- ExternalFunction::Arguments_t const &aArgs,
362+ ExternalFunction::Arguments_t const &args,
363 StaticContext const*,
364 DynamicContext const* ) const
365 {
366- String const path( getFilePathString( aArgs, 0 ) );
367+ String const path( getPathArg( args, 0 ) );
368
369 fs::info info;
370 if ( !fs::get_type( path, &info ) )
371@@ -568,11 +609,11 @@
372
373 ItemSequence_t
374 SizeFunction::evaluate(
375- ExternalFunction::Arguments_t const &aArgs,
376+ ExternalFunction::Arguments_t const &args,
377 StaticContext const*,
378 DynamicContext const* ) const
379 {
380- String const path( getFilePathString( aArgs, 0 ) );
381+ String const path( getPathArg( args, 0 ) );
382
383 fs::info info;
384 if ( !fs::get_type( path, &info ) )
385@@ -593,7 +634,7 @@
386
387 ItemSequence_t
388 PathSeparator::evaluate(
389- ExternalFunction::Arguments_t const &aArgs,
390+ ExternalFunction::Arguments_t const &args,
391 StaticContext const*,
392 DynamicContext const* ) const
393 {
394@@ -614,7 +655,7 @@
395
396 ItemSequence_t
397 DirectorySeparator::evaluate(
398- ExternalFunction::Arguments_t const &aArgs,
399+ ExternalFunction::Arguments_t const &args,
400 StaticContext const*,
401 DynamicContext const* ) const
402 {
403@@ -635,14 +676,17 @@
404
405 ItemSequence_t
406 ResolvePathFunction::evaluate(
407- ExternalFunction::Arguments_t const &aArgs,
408+ ExternalFunction::Arguments_t const &args,
409 StaticContext const*,
410 DynamicContext const* ) const
411 {
412- String lPathStr = getFilePathString( aArgs, 0 );
413- String lResult = pathToOSPath(lPathStr);
414-
415- return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(lResult)));
416+ String const path( getPathArg( args, 0 ) );
417+ String const result( pathToOSPath( path ) );
418+ return ItemSequence_t(
419+ new SingletonItemSequence(
420+ theModule->getItemFactory()->createString( result )
421+ )
422+ );
423 }
424
425 //*****************************************************************************
426@@ -658,17 +702,12 @@
427 StaticContext const*,
428 DynamicContext const* ) const
429 {
430- Item pathItem;
431- Iterator_t arg0_iter = args[0]->getIterator();
432- arg0_iter->open();
433- arg0_iter->next(pathItem);
434- arg0_iter->close();
435- String const path( pathItem.getStringValue() );
436+ String const path( getPathArg( args, 0 ) );
437 try {
438- String const osPath( fs::normalize_path( path ) );
439+ String const native_path( fs::normalize_path( path ) );
440 return ItemSequence_t(
441 new SingletonItemSequence(
442- theModule->getItemFactory()->createString( osPath )
443+ theModule->getItemFactory()->createString( native_path )
444 )
445 );
446 }
447@@ -686,14 +725,16 @@
448
449 ItemSequence_t
450 PathToUriFunction::evaluate(
451- ExternalFunction::Arguments_t const &aArgs,
452+ ExternalFunction::Arguments_t const &args,
453 StaticContext const*,
454 DynamicContext const* ) const
455 {
456- String lPathStr = getFilePathString( aArgs, 0 );
457- String lResult = pathToUriString(lPathStr);
458-
459- return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createAnyURI(lResult)));
460+ String const path( getPathArg( args, 0 ) );
461+ String const result = pathToUriString( path );
462+ return ItemSequence_t(
463+ new SingletonItemSequence(
464+ theModule->getItemFactory()->createAnyURI( result ) )
465+ );
466 }
467
468 //*****************************************************************************
469
470=== modified file 'modules/org/expath/ns/file.xq.src/file.h'
471--- modules/org/expath/ns/file.xq.src/file.h 2013-05-31 03:38:45 +0000
472+++ modules/org/expath/ns/file.xq.src/file.h 2013-06-12 23:56:32 +0000
473@@ -28,6 +28,22 @@
474
475 //*****************************************************************************
476
477+ class BaseNameFunction : public FileFunction
478+ {
479+ public:
480+ BaseNameFunction(const FileModule* aModule);
481+
482+ virtual String
483+ getLocalName() const { return "base-name"; }
484+
485+ virtual ItemSequence_t
486+ evaluate(const ExternalFunction::Arguments_t& args,
487+ const StaticContext* aSctxCtx,
488+ const DynamicContext* aDynCtx) const;
489+ };
490+
491+//*****************************************************************************
492+
493 class CreateDirectoryFunction : public FileFunction
494 {
495 public:
496@@ -60,6 +76,22 @@
497
498 //*****************************************************************************
499
500+ class DirNameFunction : public FileFunction
501+ {
502+ public:
503+ DirNameFunction(const FileModule* aModule);
504+
505+ virtual String
506+ getLocalName() const { return "dir-name"; }
507+
508+ virtual ItemSequence_t
509+ evaluate(const ExternalFunction::Arguments_t& args,
510+ const StaticContext* aSctxCtx,
511+ const DynamicContext* aDynCtx) const;
512+ };
513+
514+//*****************************************************************************
515+
516 class CopyFileImplFunction : public FileFunction
517 {
518 public:
519
520=== modified file 'modules/org/expath/ns/file.xq.src/file_function.cpp'
521--- modules/org/expath/ns/file.xq.src/file_function.cpp 2013-06-05 23:54:56 +0000
522+++ modules/org/expath/ns/file.xq.src/file_function.cpp 2013-06-12 23:56:32 +0000
523@@ -73,26 +73,47 @@
524 }
525
526 String
527-FileFunction::getFilePathString(
528- const ExternalFunction::Arguments_t& aArgs,
529- unsigned int aPos) const
530-{
531- String lFileArg;
532-
533- Item lItem;
534- Iterator_t args_iter = aArgs[aPos]->getIterator();
535- args_iter->open();
536- if (args_iter->next(lItem)) {
537- lFileArg = lItem.getStringValue();
538- }
539- args_iter->close();
540-
541+FileFunction::getEncodingArg(
542+ const ExternalFunction::Arguments_t& aArgs,
543+ unsigned int aPos) const
544+{
545+ String encoding( getStringArg( aArgs, aPos ) );
546+ if ( encoding.empty() )
547+ encoding = "UTF-8"; // the default file encoding
548+ return encoding;
549+}
550+
551+String
552+FileFunction::getPathArg(
553+ const ExternalFunction::Arguments_t& aArgs,
554+ unsigned int aPos) const
555+{
556+ String const path( getStringArg( aArgs, aPos ) );
557+ if ( path.empty() )
558+ return path;
559 try {
560- return fs::normalize_path(lFileArg, fs::curdir());
561+ return fs::normalize_path( path, fs::curdir() );
562 }
563 catch ( std::invalid_argument const &e ) {
564- throw raiseFileError( "FOFL9999", e.what(), lFileArg );
565- }
566+ throw raiseFileError( "FOFL9999", e.what(), path );
567+ }
568+}
569+
570+String
571+FileFunction::getStringArg(
572+ const ExternalFunction::Arguments_t& aArgs,
573+ unsigned int aPos) const
574+{
575+ String str;
576+ if ( aPos < aArgs.size() ) {
577+ Iterator_t i( aArgs[ aPos ]->getIterator() );
578+ i->open();
579+ Item item;
580+ if ( i->next( item ) )
581+ str = item.getStringValue();
582+ i->close();
583+ }
584+ return str;
585 }
586
587 String
588@@ -106,26 +127,6 @@
589 }
590
591 String
592-FileFunction::getEncodingArg(
593- const ExternalFunction::Arguments_t& aArgs,
594- unsigned int aPos) const
595-{
596- // the default file encoding
597- zorba::String lEncoding("UTF-8");
598- if (aArgs.size() > aPos) {
599- Item lEncodingItem;
600- Iterator_t arg_iter = aArgs[aPos]->getIterator();
601- arg_iter->open();
602- if (arg_iter->next(lEncodingItem)) {
603- lEncoding = fn::upper_case( lEncodingItem.getStringValue() );
604- }
605- arg_iter->close();
606- }
607-
608- return lEncoding;
609-}
610-
611-String
612 FileFunction::pathToOSPath(const String& aPath) const {
613 try {
614 return fs::normalize_path( aPath );
615@@ -213,7 +214,7 @@
616 const StaticContext*,
617 const DynamicContext* ) const
618 {
619- String const lFileStr( getFilePathString(aArgs, 0) );
620+ String const lFileStr( getPathArg(aArgs, 0) );
621
622 fs::type const fs_type = fs::get_type( lFileStr );
623 if ( fs_type && fs_type != fs::file )
624
625=== modified file 'modules/org/expath/ns/file.xq.src/file_function.h'
626--- modules/org/expath/ns/file.xq.src/file_function.h 2013-05-31 03:38:45 +0000
627+++ modules/org/expath/ns/file.xq.src/file_function.h 2013-06-12 23:56:32 +0000
628@@ -55,7 +55,7 @@
629 * pos must point to a file function argument. No checks are made.
630 */
631 String
632- getFilePathString(
633+ getPathArg(
634 const ExternalFunction::Arguments_t& args,
635 unsigned int pos) const;
636
637@@ -65,6 +65,11 @@
638 unsigned int pos) const;
639
640 String
641+ getStringArg(
642+ const ExternalFunction::Arguments_t& args,
643+ unsigned int pos) const;
644+
645+ String
646 pathToFullOSPath(const String& path) const;
647
648 String
649
650=== modified file 'modules/org/expath/ns/file.xq.src/file_module.cpp'
651--- modules/org/expath/ns/file.xq.src/file_module.cpp 2013-03-06 02:54:03 +0000
652+++ modules/org/expath/ns/file.xq.src/file_module.cpp 2013-06-12 23:56:32 +0000
653@@ -38,26 +38,30 @@
654 {
655 ExternalFunction*& lFunc = theFunctions[aLocalname];
656 if (!lFunc) {
657- if (aLocalname == "create-directory") {
658+ if (aLocalname == "base-name") {
659+ lFunc = new BaseNameFunction(this);
660+ } else if (aLocalname == "copy-file-impl") {
661+ lFunc = new CopyFileImplFunction(this);
662+ } else if (aLocalname == "create-directory") {
663 lFunc = new CreateDirectoryFunction(this);
664 } else if (aLocalname == "delete-file-impl") {
665 lFunc = new DeleteFileImplFunction(this);
666+ } else if (aLocalname == "dir-name") {
667+ lFunc = new DirNameFunction(this);
668+ } else if (aLocalname == "exists") {
669+ lFunc = new ExistsFunction(this);
670+ } else if (aLocalname == "is-directory") {
671+ lFunc = new IsDirectoryFunction(this);
672+ } else if (aLocalname == "is-file") {
673+ lFunc = new IsFileFunction(this);
674 } else if (aLocalname == "read-binary") {
675 lFunc = new ReadBinaryFunction(this);
676 } else if (aLocalname == "read-text") {
677 lFunc = new ReadTextFunction(this);
678 } else if (aLocalname == "read-text-lines") {
679 lFunc = new ReadTextLinesFunction(this);
680- } else if (aLocalname == "exists") {
681- lFunc = new ExistsFunction(this);
682- } else if (aLocalname == "is-directory") {
683- lFunc = new IsDirectoryFunction(this);
684- } else if (aLocalname == "is-file") {
685- lFunc = new IsFileFunction(this);
686 } else if (aLocalname == "is-symlink") {
687 lFunc = new IsSymlinkFunction(this);
688- } else if (aLocalname == "copy-file-impl") {
689- lFunc = new CopyFileImplFunction(this);
690 } else if (aLocalname == "write-text") {
691 lFunc = new WriteTextFunction(this);
692 } else if (aLocalname == "write-binary") {
693
694=== modified file 'src/util/time_util.h'
695--- src/util/time_util.h 2013-06-01 00:30:39 +0000
696+++ src/util/time_util.h 2013-06-12 23:56:32 +0000
697@@ -124,7 +124,7 @@
698 *
699 * @param mon The month to convert: [0-11].
700 * @param to The calendar designator to convert \a mon to.
701- * @return Returns \a mon converted to \a to or -1 if is unknown hot to
702+ * @return Returns \a mon converted to \a to or -1 if is unknown how to
703 * perform the conversion.
704 */
705 int convert_mon_to( unsigned mon, type to );
706
707=== added file 'test/rbkt/ExpQueryResults/zorba/file/dirname_basename-00.xml.res'
708--- test/rbkt/ExpQueryResults/zorba/file/dirname_basename-00.xml.res 1970-01-01 00:00:00 +0000
709+++ test/rbkt/ExpQueryResults/zorba/file/dirname_basename-00.xml.res 2013-06-12 23:56:32 +0000
710@@ -0,0 +1,1 @@
711+true
712
713=== added file 'test/rbkt/ExpQueryResults/zorba/file/dirname_basename-01.xml.res'
714--- test/rbkt/ExpQueryResults/zorba/file/dirname_basename-01.xml.res 1970-01-01 00:00:00 +0000
715+++ test/rbkt/ExpQueryResults/zorba/file/dirname_basename-01.xml.res 2013-06-12 23:56:32 +0000
716@@ -0,0 +1,1 @@
717+true
718
719=== added file 'test/rbkt/ExpQueryResults/zorba/file/dirname_basename-02.xml.res'
720--- test/rbkt/ExpQueryResults/zorba/file/dirname_basename-02.xml.res 1970-01-01 00:00:00 +0000
721+++ test/rbkt/ExpQueryResults/zorba/file/dirname_basename-02.xml.res 2013-06-12 23:56:32 +0000
722@@ -0,0 +1,1 @@
723+true
724
725=== added file 'test/rbkt/ExpQueryResults/zorba/file/dirname_basename-03.xml.res'
726--- test/rbkt/ExpQueryResults/zorba/file/dirname_basename-03.xml.res 1970-01-01 00:00:00 +0000
727+++ test/rbkt/ExpQueryResults/zorba/file/dirname_basename-03.xml.res 2013-06-12 23:56:32 +0000
728@@ -0,0 +1,1 @@
729+true
730
731=== added file 'test/rbkt/ExpQueryResults/zorba/file/dirname_basename-04.xml.res'
732--- test/rbkt/ExpQueryResults/zorba/file/dirname_basename-04.xml.res 1970-01-01 00:00:00 +0000
733+++ test/rbkt/ExpQueryResults/zorba/file/dirname_basename-04.xml.res 2013-06-12 23:56:32 +0000
734@@ -0,0 +1,1 @@
735+true
736
737=== added file 'test/rbkt/ExpQueryResults/zorba/file/dirname_basename-05.xml.res'
738--- test/rbkt/ExpQueryResults/zorba/file/dirname_basename-05.xml.res 1970-01-01 00:00:00 +0000
739+++ test/rbkt/ExpQueryResults/zorba/file/dirname_basename-05.xml.res 2013-06-12 23:56:32 +0000
740@@ -0,0 +1,1 @@
741+true
742
743=== added file 'test/rbkt/ExpQueryResults/zorba/file/dirname_basename-06.xml.res'
744--- test/rbkt/ExpQueryResults/zorba/file/dirname_basename-06.xml.res 1970-01-01 00:00:00 +0000
745+++ test/rbkt/ExpQueryResults/zorba/file/dirname_basename-06.xml.res 2013-06-12 23:56:32 +0000
746@@ -0,0 +1,1 @@
747+true
748
749=== removed file 'test/rbkt/ExpQueryResults/zorba/file/dirname_basename.xml.res'
750--- test/rbkt/ExpQueryResults/zorba/file/dirname_basename.xml.res 2013-02-07 17:24:36 +0000
751+++ test/rbkt/ExpQueryResults/zorba/file/dirname_basename.xml.res 1970-01-01 00:00:00 +0000
752@@ -1,1 +0,0 @@
753-true
754
755=== added file 'test/rbkt/Queries/zorba/file/dirname_basename-00.xq'
756--- test/rbkt/Queries/zorba/file/dirname_basename-00.xq 1970-01-01 00:00:00 +0000
757+++ test/rbkt/Queries/zorba/file/dirname_basename-00.xq 2013-06-12 23:56:32 +0000
758@@ -0,0 +1,16 @@
759+import module namespace file = "http://expath.org/ns/file";
760+import module namespace sys = "http://www.zorba-xquery.com/modules/system";
761+
762+declare function local:do( $path ) {
763+ fn:concat( file:dir-name( $path ), '-', file:base-name( $path ) )
764+};
765+
766+if ( sys:property($sys:os-name) eq "Windows" )
767+then
768+ let $path := "C:\a\b.txt"
769+ return file:base-name( $path, ".txt" ) eq "b"
770+else
771+ let $path := "/a/b.txt"
772+ return file:base-name( $path, ".txt" ) eq "b"
773+
774+(: vim:set et sw=2 ts=2: :)
775
776=== added file 'test/rbkt/Queries/zorba/file/dirname_basename-01.xq'
777--- test/rbkt/Queries/zorba/file/dirname_basename-01.xq 1970-01-01 00:00:00 +0000
778+++ test/rbkt/Queries/zorba/file/dirname_basename-01.xq 2013-06-12 23:56:32 +0000
779@@ -0,0 +1,16 @@
780+import module namespace file = "http://expath.org/ns/file";
781+import module namespace sys = "http://www.zorba-xquery.com/modules/system";
782+
783+declare function local:do( $path ) {
784+ fn:concat( file:dir-name( $path ), '|', file:base-name( $path ) )
785+};
786+
787+if ( sys:property($sys:os-name) eq "Windows" )
788+then
789+ let $path := "C:\a\b"
790+ return local:do( $path ) eq "C:\a|b"
791+else
792+ let $path := "/a/b"
793+ return local:do( $path ) eq "/a|b"
794+
795+(: vim:set et sw=2 ts=2: :)
796
797=== added file 'test/rbkt/Queries/zorba/file/dirname_basename-02.xq'
798--- test/rbkt/Queries/zorba/file/dirname_basename-02.xq 1970-01-01 00:00:00 +0000
799+++ test/rbkt/Queries/zorba/file/dirname_basename-02.xq 2013-06-12 23:56:32 +0000
800@@ -0,0 +1,16 @@
801+import module namespace file = "http://expath.org/ns/file";
802+import module namespace sys = "http://www.zorba-xquery.com/modules/system";
803+
804+declare function local:do( $path ) {
805+ fn:concat( file:dir-name( $path ), '|', file:base-name( $path ) )
806+};
807+
808+if ( sys:property($sys:os-name) eq "Windows" )
809+then
810+ let $path := "C:\a"
811+ return local:do( $path ) eq "C:\|a"
812+else
813+ let $path := "/a"
814+ return local:do( $path ) eq "/|a"
815+
816+(: vim:set et sw=2 ts=2: :)
817
818=== added file 'test/rbkt/Queries/zorba/file/dirname_basename-03.xq'
819--- test/rbkt/Queries/zorba/file/dirname_basename-03.xq 1970-01-01 00:00:00 +0000
820+++ test/rbkt/Queries/zorba/file/dirname_basename-03.xq 2013-06-12 23:56:32 +0000
821@@ -0,0 +1,16 @@
822+import module namespace file = "http://expath.org/ns/file";
823+import module namespace sys = "http://www.zorba-xquery.com/modules/system";
824+
825+declare function local:do( $path ) {
826+ fn:concat( file:dir-name( $path ), '|', file:base-name( $path ) )
827+};
828+
829+if ( sys:property($sys:os-name) eq "Windows" )
830+then
831+ let $path := "C:\"
832+ return local:do( $path ) eq "C:\|C:\"
833+else
834+ let $path := "/"
835+ return local:do( $path ) eq "/|/"
836+
837+(: vim:set et sw=2 ts=2: :)
838
839=== added file 'test/rbkt/Queries/zorba/file/dirname_basename-04.xq'
840--- test/rbkt/Queries/zorba/file/dirname_basename-04.xq 1970-01-01 00:00:00 +0000
841+++ test/rbkt/Queries/zorba/file/dirname_basename-04.xq 2013-06-12 23:56:32 +0000
842@@ -0,0 +1,16 @@
843+import module namespace file = "http://expath.org/ns/file";
844+import module namespace sys = "http://www.zorba-xquery.com/modules/system";
845+
846+declare function local:do( $path ) {
847+ fn:concat( file:dir-name( $path ), '|', file:base-name( $path ) )
848+};
849+
850+if ( sys:property($sys:os-name) eq "Windows" )
851+then
852+ let $path := "a\b"
853+ return local:do( $path ) eq "a|b"
854+else
855+ let $path := "a/b"
856+ return local:do( $path ) eq "a|b"
857+
858+(: vim:set et sw=2 ts=2: :)
859
860=== added file 'test/rbkt/Queries/zorba/file/dirname_basename-05.xq'
861--- test/rbkt/Queries/zorba/file/dirname_basename-05.xq 1970-01-01 00:00:00 +0000
862+++ test/rbkt/Queries/zorba/file/dirname_basename-05.xq 2013-06-12 23:56:32 +0000
863@@ -0,0 +1,10 @@
864+import module namespace file = "http://expath.org/ns/file";
865+
866+declare function local:do( $path ) {
867+ fn:concat( file:dir-name( $path ), '|', file:base-name( $path ) )
868+};
869+
870+let $path := "a"
871+return local:do( $path ) eq ".|a"
872+
873+(: vim:set et sw=2 ts=2: :)
874
875=== added file 'test/rbkt/Queries/zorba/file/dirname_basename-06.xq'
876--- test/rbkt/Queries/zorba/file/dirname_basename-06.xq 1970-01-01 00:00:00 +0000
877+++ test/rbkt/Queries/zorba/file/dirname_basename-06.xq 2013-06-12 23:56:32 +0000
878@@ -0,0 +1,16 @@
879+import module namespace file = "http://expath.org/ns/file";
880+import module namespace sys = "http://www.zorba-xquery.com/modules/system";
881+
882+declare function local:do( $path ) {
883+ fn:concat( file:dir-name( $path ), '|', file:base-name( $path ) )
884+};
885+
886+if ( sys:property($sys:os-name) eq "Windows" )
887+then
888+ let $path := "C:\a\\\"
889+ return local:do( $path ) eq "C:\|a"
890+else
891+ let $path := "/a///"
892+ return local:do( $path ) eq "/|a"
893+
894+(: vim:set et sw=2 ts=2: :)
895
896=== removed file 'test/rbkt/Queries/zorba/file/dirname_basename.spec'
897--- test/rbkt/Queries/zorba/file/dirname_basename.spec 2013-01-21 09:00:53 +0000
898+++ test/rbkt/Queries/zorba/file/dirname_basename.spec 1970-01-01 00:00:00 +0000
899@@ -1,2 +0,0 @@
900-Args:
901-Error: http://www.w3.org/2005/xqt-errors:XQST0059
902
903=== removed file 'test/rbkt/Queries/zorba/file/dirname_basename.xq'
904--- test/rbkt/Queries/zorba/file/dirname_basename.xq 2013-02-07 17:24:36 +0000
905+++ test/rbkt/Queries/zorba/file/dirname_basename.xq 1970-01-01 00:00:00 +0000
906@@ -1,64 +0,0 @@
907-import module namespace sys = 'http://www.zorba-xquery.com/modules/system';
908-import module namespace file = "http://expath.org/ns/file";
909-
910-declare function local:do($path) {
911- fn:concat(file:dir-name($path),"-",file:base-name($path))
912-};
913-
914-if (sys:property($sys:os-name) eq "Windows") then
915- let $path0 := "C:\a\b\abcd\\\"
916- let $path1 := "c:/a/b/c////"
917- let $path2 := "D:/a/b/c"
918- let $path3 := "d:\a\b\c\\\\"
919- let $path4 := "E:\a\b\c"
920- let $path5 := "file:///e:/a/b/c////"
921- let $path6 := "file:///F:/a/b/c"
922- let $path7 := "f:////"
923- let $path8 := "G:\\\\\"
924- let $path9 := "g:"
925- let $path10 := "H:\"
926- let $path12 := "file:///I:/"
927- let $path13 := "file:///i:///"
928- return
929- (
930- file:base-name($path0, "cd") eq "ab" and
931- local:do($path1) eq "c:\a\b-c" and
932- local:do($path2) eq "D:\a\b-c" and
933- local:do($path3) eq "d:\a\b-c" and
934- local:do($path4) eq "E:\a\b-c" and
935- local:do($path5) eq "e:\a\b-c" and
936- local:do($path6) eq "F:\a\b-c" and
937- local:do($path7) eq "f:\-" and
938- local:do($path8) eq "G:\-" and
939- local:do($path9) eq "g:\-" and
940- local:do($path10) eq "H:\-" and
941- local:do($path12) eq "I:\-" and
942- local:do($path13) eq "i:\-"
943- )
944-else
945- let $path0 := "/a/b/abcd///"
946- let $path1 := "/a/b/c////"
947- let $path2 := "/a/b/c"
948- let $path3 := "\a\b\c\\\\"
949- let $path4 := "\a\b\c"
950- let $path5 := "file:///a/b/c////"
951- let $path6 := "file:///a/b/c"
952- let $path7 := "////"
953- let $path8 := "\\\\\"
954- let $path9 := "/"
955- let $path10 := "file:///"
956- return
957- (
958- file:base-name($path0, "cd") eq "ab" and
959- local:do($path1) eq "/a/b-c" and
960- local:do($path2) eq "/a/b-c" and
961- local:do($path3) eq "/a/b-c" and
962- local:do($path4) eq "/a/b-c" and
963- local:do($path5) eq "/a/b-c" and
964- local:do($path6) eq "/a/b-c" and
965- local:do($path7) eq "/-" and
966- local:do($path8) eq "/-" and
967- local:do($path9) eq "/-" and
968- local:do($path10) eq "/-"
969- )
970-

Subscribers

People subscribed via source and target branches