Modify

Opened 4 months ago

Last modified 4 months ago

#3892 assigned Feature Request

Func() Pass Parameter Bynames

Reported by: Jpm Owned by: Jpm
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:

Description (last modified by mLipok)

Instead of skipping parameter not need using a Default keyword
the Func() syntax can be

Func functioname ( [ [Const] [ByRef] $param1, ... ,] [ [ByNames] [ByRef] $optionalpar1 = value, ... ] )

so the function can be for _PathSplit()

#include <Array.au3>
#include <File.au3>

;read in an array only
Local $aPathSplit = _PathSplit_ByNames(@ScriptFullPath) ; , $sDrive, $sDir, $sFileName, $sExtension)
_ArrayDisplay($aPathSplit, "_PathSplit_ByNames of " & @ScriptFullPath)

; read just the folder part
Local $sFolder = ""
_PathSplit_ByNames(@ScriptFullPath, sDir = $sFolder)
MsgBox(0, "Folder", $sFolder)

Func _PathSplit_ByNames($sFilePath, BYNAMES ByRef $sDrive = ByDefault, ByRef $sDir = ByDefault, ByRef $sFileName = ByDefault, ByRef $sExtension = ByDefault)
        Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH)
        If @error Then ; This error should never happen.
                ReDim $aArray[5]
                $aArray[$PATH_ORIGINAL] = $sFilePath
        EndIf
        Local $KEYWORD_BYDEFAULT = 3 ; if AutoItConstants.au3 is not updated
        If IsKeyWord($sDrive) <> $KEYWORD_BYDEFAULT Then $sDrive = $aArray[$PATH_DRIVE]

        Local $sTemp
        If StringLeft($aArray[$PATH_DIRECTORY], 1) == "/" Then
                $sTemp = StringRegExpReplace($aArray[$PATH_DIRECTORY], "\h*[\/\\]+\h*", "\/")
        Else
                $sTemp = StringRegExpReplace($aArray[$PATH_DIRECTORY], "\h*[\/\\]+\h*", "\\")
        EndIf
        $aArray[$PATH_DIRECTORY] = $sTemp

        If IsKeyWord($sDir) <> $KEYWORD_BYDEFAULT Then $sDir = $sTemp
        If IsKeyWord($sFileName) <> $KEYWORD_BYDEFAULT Then $sFileName = $aArray[$PATH_FILENAME]
        If IsKeyWord($sExtension) <> $KEYWORD_BYDEFAULT Then $sExtension = $aArray[$PATH_EXTENSION]

        Return $aArray
EndFunc   ;==>_PathSplit_ByNames

a ByDefault keyword is also usefull if the caller calling with Default is to be handled differently than an parameter being optional

Attachments (0)

Change History (2)

comment:1 Changed 4 months ago by Jpm

  • Owner set to Jpm
  • Status changed from new to assigned

Fix sent to Jon

comment:2 Changed 4 months ago by mLipok

  • Description modified (diff)

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as assigned The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.