← Back to team overview

zorba-coders team mailing list archive

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

 

Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

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.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/168983

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.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/168983
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2013-06-11 23:35:24 +0000
+++ ChangeLog	2013-06-12 15:40:46 +0000
@@ -22,6 +22,7 @@
   * Fixed bug #1188084 (fn-replace-42 failing)
   * Fixed bug in hoisting through try-catch expr
   * Fixed bug #1162631 (format-integer 'w' format of negative numbers)
+  * Fixed bug #1190261 (relative paths bug in file module)
   * Fixed bug #1180220 (Consolidate redundant path/file public APIs)
   * Fixed bug #1103115 (Timezone units as hours are wrong)
   * Fixed implementation of fn:deep-equal according to latest W3C spec.

=== modified file 'modules/org/expath/ns/file.xq'
--- modules/org/expath/ns/file.xq	2013-06-06 20:56:08 +0000
+++ modules/org/expath/ns/file.xq	2013-06-12 15:40:46 +0000
@@ -751,29 +751,7 @@
  : @param $path A file path/URI.
  : @return The base name of this file.
  :)
-declare function file:base-name($path as xs:string) as xs:string
-{
-  let $delim := file:directory-separator()
-  let $escapedDelim :=
-    if ($delim eq "/") then
-      $delim
-    else
-      fn:concat("\", $delim)
-  let $normalized-file := 
-    let $n := file:prepare-for-dirname-and-base-name($path)
-    return if ($delim eq "\" and fn:matches($n, "^[a-zA-Z]:$")) then
-      fn:concat($n, "\")
-    else $n
-  return
-    if (fn:matches($path, fn:concat("^", $escapedDelim, "+$"))) then
-      ""
-    else if ($delim eq "\" and fn:matches($path, "^[a-zA-Z]:\\?$")) then
-      ""
-    else if ($path eq "") then
-      "."
-    else
-      fn:replace($normalized-file, fn:concat("^.*", $escapedDelim), "")
-};
+declare function file:base-name($path as xs:string) as xs:string external;
 
 (:~
  : Returns the last component from the <pre>$path</pre>, deleting any
@@ -812,50 +790,6 @@
  : @param $path The filename, of which the dirname should be get.
  : @return The name of the directory the file is in.
  :)
-declare function file:dir-name($path as xs:string) as xs:string
-{
-  let $delim := file:directory-separator()
-  let $escapedDelim :=
-    if ($delim eq "/") then
-      $delim
-    else
-      fn:concat("\", $delim)
-  let $normalized-file := file:prepare-for-dirname-and-base-name($path)
-  return
-    if (fn:matches($path, fn:concat("^", $escapedDelim, "+$"))) then
-      $delim
-    else if ($normalized-file eq $delim) then
-      $delim
-    else if ($delim eq "\" and fn:matches($path, "^[a-zA-Z]:\\$")) then
-      $path
-    else if ($delim eq "\" and fn:matches($normalized-file, "^[a-zA-Z]:$")) then
-      fn:concat($normalized-file, '\')
-    else if ($path eq "") then
-      "."
-    else if (fn:matches($normalized-file, $escapedDelim)) then
-      fn:replace($normalized-file, fn:concat("^(.*)", $escapedDelim, ".*"), "$1")
-    else
-      "."
-};
+declare function file:dir-name($path as xs:string) as xs:string external;
 
-(:~
- : This is a helper function used by dirname and base-name. This function takes a path as
- : input and normalizes it according to the rules states in dirname/base-name documentation
- : and normalizes it to a system specific path.
- :)
-declare %private function file:prepare-for-dirname-and-base-name($path as xs:string) as xs:string
-{
-  let $delim := file:directory-separator()
-  let $escapedDelim :=
-    if ($delim eq "/") then
-      $delim
-    else
-      fn:concat("\", $delim)
-  let $normalize-path := file:path-to-native($path)
-  let $normalized :=
-    if ($normalize-path eq $delim) then
-      $normalize-path
-    else
-      fn:replace($normalize-path, fn:concat($escapedDelim, "+$"), "")
-  return $normalized
-};
+(: vim:set et sw=2 ts=2: :)

=== modified file 'modules/org/expath/ns/file.xq.src/file.cpp'
--- modules/org/expath/ns/file.xq.src/file.cpp	2013-06-04 05:33:22 +0000
+++ modules/org/expath/ns/file.xq.src/file.cpp	2013-06-12 15:40:46 +0000
@@ -41,6 +41,25 @@
 
 //*****************************************************************************
 
+BaseNameFunction::BaseNameFunction(const FileModule* aModule)
+  : FileFunction(aModule)
+{
+}
+
+ItemSequence_t
+BaseNameFunction::evaluate(
+  ExternalFunction::Arguments_t const &aArgs,
+  StaticContext const*,
+  DynamicContext const* ) const
+{
+  String const path( getFilePathString( aArgs, 0 ) );
+  String const base_name( fs::base_name( path ) );
+  Item item( theModule->getItemFactory()->createString( base_name ) );
+  return ItemSequence_t( new SingletonItemSequence( item ) );
+}
+
+//*****************************************************************************
+
 CreateDirectoryFunction::CreateDirectoryFunction(const FileModule* aModule)
   : FileFunction(aModule)
 {
@@ -97,6 +116,25 @@
 
 //*****************************************************************************
 
+DirNameFunction::DirNameFunction(const FileModule* aModule)
+  : FileFunction(aModule)
+{
+}
+
+ItemSequence_t
+DirNameFunction::evaluate(
+  ExternalFunction::Arguments_t const &aArgs,
+  StaticContext const*,
+  DynamicContext const* ) const
+{
+  String const path( getFilePathString( aArgs, 0 ) );
+  String const dir_name( fs::dir_name( path ) );
+  Item item( theModule->getItemFactory()->createString( dir_name ) );
+  return ItemSequence_t( new SingletonItemSequence( item ) );
+}
+
+//*****************************************************************************
+
 ReadBinaryFunction::ReadBinaryFunction( FileModule const *aModule ) :
   FileFunction( aModule )
 {

=== modified file 'modules/org/expath/ns/file.xq.src/file.h'
--- modules/org/expath/ns/file.xq.src/file.h	2013-05-31 03:38:45 +0000
+++ modules/org/expath/ns/file.xq.src/file.h	2013-06-12 15:40:46 +0000
@@ -28,6 +28,22 @@
 
 //*****************************************************************************
 
+  class BaseNameFunction : public FileFunction
+  {
+    public:
+      BaseNameFunction(const FileModule* aModule);
+
+      virtual String
+      getLocalName() const { return "base-name"; }
+  
+      virtual ItemSequence_t 
+      evaluate(const ExternalFunction::Arguments_t& args,
+               const StaticContext* aSctxCtx,
+               const DynamicContext* aDynCtx) const;
+  };
+
+//*****************************************************************************
+
   class CreateDirectoryFunction : public FileFunction
   {
     public:
@@ -60,6 +76,22 @@
 
 //*****************************************************************************
 
+  class DirNameFunction : public FileFunction
+  {
+    public:
+      DirNameFunction(const FileModule* aModule);
+
+      virtual String
+      getLocalName() const { return "dir-name"; }
+  
+      virtual ItemSequence_t 
+      evaluate(const ExternalFunction::Arguments_t& args,
+               const StaticContext* aSctxCtx,
+               const DynamicContext* aDynCtx) const;
+  };
+
+//*****************************************************************************
+
   class CopyFileImplFunction : public FileFunction
   {
     public:

=== modified file 'modules/org/expath/ns/file.xq.src/file_module.cpp'
--- modules/org/expath/ns/file.xq.src/file_module.cpp	2013-03-06 02:54:03 +0000
+++ modules/org/expath/ns/file.xq.src/file_module.cpp	2013-06-12 15:40:46 +0000
@@ -38,26 +38,30 @@
 {
   ExternalFunction*& lFunc = theFunctions[aLocalname];
   if (!lFunc) {
-    if (aLocalname == "create-directory") {
+    if (aLocalname == "base-name") {
+      lFunc = new BaseNameFunction(this);
+    } else if (aLocalname == "copy-file-impl") {
+      lFunc = new CopyFileImplFunction(this);
+    } else if (aLocalname == "create-directory") {
       lFunc = new CreateDirectoryFunction(this);
     } else if (aLocalname == "delete-file-impl") {
       lFunc = new DeleteFileImplFunction(this);
+    } else if (aLocalname == "dir-name") {
+      lFunc = new DirNameFunction(this);
+    } else if (aLocalname == "exists") {
+      lFunc = new ExistsFunction(this);
+    } else if (aLocalname == "is-directory") {
+      lFunc = new IsDirectoryFunction(this);
+    } else if (aLocalname == "is-file") {
+      lFunc = new IsFileFunction(this);
     } else if (aLocalname == "read-binary") {
       lFunc = new ReadBinaryFunction(this);
     } else if (aLocalname == "read-text") {
       lFunc = new ReadTextFunction(this);
     } else if (aLocalname == "read-text-lines") {
       lFunc = new ReadTextLinesFunction(this);
-    } else if (aLocalname == "exists") {
-      lFunc = new ExistsFunction(this);
-    } else if (aLocalname == "is-directory") {
-      lFunc = new IsDirectoryFunction(this);
-    } else if (aLocalname == "is-file") {
-      lFunc = new IsFileFunction(this);
     } else if (aLocalname == "is-symlink") {
       lFunc = new IsSymlinkFunction(this);
-    } else if (aLocalname == "copy-file-impl") {
-      lFunc = new CopyFileImplFunction(this);
     } else if (aLocalname == "write-text") {
       lFunc = new WriteTextFunction(this);
     } else if (aLocalname == "write-binary") {

=== modified file 'src/util/time_util.h'
--- src/util/time_util.h	2013-06-01 00:30:39 +0000
+++ src/util/time_util.h	2013-06-12 15:40:46 +0000
@@ -124,7 +124,7 @@
    *
    * @param mon The month to convert: [0-11].
    * @param to The calendar designator to convert \a mon to.
-   * @return Returns \a mon converted to \a to or -1 if is unknown hot to
+   * @return Returns \a mon converted to \a to or -1 if is unknown how to
    * perform the conversion.
    */
   int convert_mon_to( unsigned mon, type to );


Follow ups