You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/04/01 08:20:25 UTC

[jira] [Commented] (JENA-967) Suggested ARQ Extension function: afn:printf(...)

    [ https://issues.apache.org/jira/browse/JENA-967?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15221229#comment-15221229 ] 

ASF GitHub Bot commented on JENA-967:
-------------------------------------

GitHub user ales004 opened a pull request:

    https://github.com/apache/jena/pull/132

    afn:Sprintf implementation (JENA-967)

    Hi,
    I implemented the afn:sprintf function. In order to implement it, I had to:
    
    - create a sprintf.java class in the sparql function part.
    
    - implement in the XSDFuncOp.java a function dealing with making sprintf
    
    - create a series of tests checking that the function is working correctly.
    
    While implementing, I realized that the example described in the bug is just one of the possibilities (printing numbers) as by the Java specification, String.Format works with all types. I thus implemented the function to work with all the type that made sense in my opinion (we can discuss about this).
    
    There is still one problem that I am not sure how to solve:
    Test 04 and 07 and 08 depend on the user locale (it will be printed as 1.2.. or 1,2.. or with date the day or month depend on the locale). In order to solve this, we will need to show to String.Format the current locale but I could not find a way to do this from the XSDFuncOp class.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ales004/jena master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/jena/pull/132.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #132
    
----
commit e2b7c9a9f1c922f8290c704465483e30f9178ef9
Author: ales004 <ci...@hotmail.com>
Date:   2016-03-17T20:09:47Z

    Correct a small typo in the TestFunctions2 file.

commit a0cea2c45a4bc9ed2cfb6601c253e702d9ff5751
Author: ales004 <ci...@hotmail.com>
Date:   2016-03-17T20:07:25Z

    Implemented the afn:sprintf function that uses the String.format Java function to format an input value to string. In the current implementation, the input value can be a number, a string, a date or a datetime value. Other types are not accepted.

----


> Suggested ARQ Extension function: afn:printf(...)
> -------------------------------------------------
>
>                 Key: JENA-967
>                 URL: https://issues.apache.org/jira/browse/JENA-967
>             Project: Apache Jena
>          Issue Type: New Feature
>          Components: ARQ
>            Reporter: Stuart Williams
>            Priority: Minor
>
> There are situations where it would be useful to be able to format strings bound to variable. In particular I have wanted to create some zero-filled numeric strings.
> I've accomplished the task with a pair of BINDs as follows where {{?code}} is bound to a numeric string:
> {noformat}
>    BIND( "000000" as ?zfill )
>    BIND( concat(if(strlen(?code)>=strlen(?zfill),"",substr(?zfill,strlen(?code)+1)),?code) as ?reg_notation)
> {noformat}
> But it would have been nice to be able to use something less opaque like:
> {noformat}
>    BIND( afn:printf("%06d",?code) as ?reg_notation)
> {noformat}
> So 'improvement'/'new feature' suggestion is an additional ARQ Extension function that exposes java {{printf}} method.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)