[GitHub] jena pull request: JENA-967: afn:Sprintf implementation

2016-04-11 Thread afs
Github user afs commented on the pull request:

https://github.com/apache/jena/pull/132#issuecomment-208295483
  
Looks good and I've merged it into master. Thanks!

(I've added t the documentation for the function library.)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-967: afn:Sprintf implementation

2016-04-11 Thread asfgit
Github user asfgit closed the pull request at:

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-967: afn:Sprintf implementation

2016-04-10 Thread ales004
Github user ales004 commented on the pull request:

https://github.com/apache/jena/pull/132#issuecomment-208077486
  
I think that commit bf14c982b8ae3eb8f040f55c28f8262efb5dad01 should do what 
you asked:

- now also tests are Locale dependent.
- sprintf accepts any number of arguments.
- unkwnown classes are translated to string using the function you pointed 
out.

What do you think?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-967: afn:Sprintf implementation

2016-04-06 Thread afs
Github user afs commented on the pull request:

https://github.com/apache/jena/pull/132#issuecomment-206374357
  
For now, I think that "local locale" is the best single choice because if 
the user wants the XSD standard form "1.23" they can workaround it with a call 
`str()` and print a string. Not perfect but gives them a way.

XSD F&O v3.1 has "picture strings" : 
https://www.w3.org/TR/xpath-functions-3/#dt-picture-string : that looks like 
Java DecimalFormat, not printf style.

I think most people are familiar with printf and things like padding 
strings and alignment are covered. We can refine the capabilities after the 
machinery is in.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-967: afn:Sprintf implementation

2016-04-05 Thread ales004
Github user ales004 commented on a diff in the pull request:

https://github.com/apache/jena/pull/132#discussion_r58619008
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java ---
@@ -352,6 +352,60 @@ public static NodeValue javaSubstring(NodeValue 
nvString, NodeValue nvStart, Nod
 }
 }
 
+// expecting nvString = format | nvStart = value (int,float, 
string,)
+public static NodeValue javaSprintf(NodeValue nvFormat, NodeValue 
nvValue) {
+try {
+String formatForOutput = nvFormat.getString() ;
+ValueSpaceClassification vlSpClass = nvValue.getValueSpace();
+switch(vlSpClass){
+case VSPACE_NUM:
+NumericType type = 
classifyNumeric("javaSprintf",nvValue);
+switch(type) {
+case OP_DECIMAL:
+BigDecimal decimalValue = nvValue.getDecimal();
+return 
NodeValue.makeString(String.format(formatForOutput,decimalValue)) ;
+case OP_INTEGER:
+BigInteger integerValue = nvValue.getInteger();
+return 
NodeValue.makeString(String.format(formatForOutput,integerValue)) ;
+case OP_DOUBLE:
+Double doubValue = nvValue.getDouble();
+return 
NodeValue.makeString(String.format(formatForOutput,doubValue)) ;
+case OP_FLOAT:
+Float floatValue = nvValue.getFloat();
+return 
NodeValue.makeString(String.format(formatForOutput,floatValue)) ;
--- End diff --

Depending on the Locale: 1.23 can be printed as 1.23 or 1,23


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-967: afn:Sprintf implementation

2016-04-05 Thread ales004
Github user ales004 commented on the pull request:

https://github.com/apache/jena/pull/132#issuecomment-205996315
  
Yes I think that the idea about the list is very good. I will try to 
implement it like this.

I am still wondering what to do with the String.Format for Double, Float 
and Datetime that depend on the Locale. What do you think about this?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-967: afn:Sprintf implementation

2016-04-05 Thread afs
Github user afs commented on the pull request:

https://github.com/apache/jena/pull/132#issuecomment-205936352
  
>  These cases for the moment are not supported. Maybe we could treat them 
all like strings.

Yes - `NodeFunction.str(NodeValue)` can be used to get the lexical form.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-967: afn:Sprintf implementation

2016-04-05 Thread afs
Github user afs commented on the pull request:

https://github.com/apache/jena/pull/132#issuecomment-205935091
  
Hi - looks good 

One suggestion : Java printf can take a variable number of arguments from 
zero upwards.

It would be nice if `afn:sprintf("%d != %d", 1, 2)` worked.  Could the 
arguments (args 1 on) go into a list, and javaSprintf proces them into a a 
Object[] for String.format?



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---