NAnt: cannot resolve to boolean value - if-statement

<if test="${deployErrors} > 0">
<fail message="MSDeploy failed" />
</if>
${deployErrors} is populated from a regex capture group and either has a numeric value or empty string. How can I check if this is greater than 0 in a NAnt if block? Here's the error I'm getting if deploy errors contains '1'
'1 > 0' is not a valid value for
attribute 'test' of .
Cannot resolve '1 > 0' to boolean value.
String was not recognized as a valid Boolean.

I've not tried it, but I think you need the whole of your expression within the curly braces:
<if test="${deployErrors > 0}">
See also the second example in the documentation page.
Update from OP:
This worked:
<if test="${deployErrors != ''}">

If you need to do something with the actual numeric value then you could do something like this:
<if test="${int::parse('0' + deployErrors) > 10}">

Similar to Trystan's answer - to parse a string to a bool, for a string e.g. true, false
<if test="${bool::parse(isEnabled)}">
From http://nant.sourceforge.net/release/0.85/help/functions/bool.parse.html

Related

Regex in XML using PHP: find certain value of a certain xml tag

I am trying to get the value of a certain attribute in a certain xml tag with regex but cant get it right, maybe someone has an idea how to do it?
The xml looks like this:
<OTA_PingRQ>
<Errors>
<Error Code="101" Type="4" Status="NotProcessed" ShortText="Authentication refused">Authentication : login failed</Error>
</Errors>
</OTA_PingRQ>
and id like to match only the value of the Shorttext inside the Error tag.
in the end it should give me "Authentication refused" back.
What ive tried so far is using a lookbehind and lookahead, which doesnt let me take quantifiers with non fixed width. Like that (?<=<Error .).*?(?=>).
Can someone tell me how to only match the value of the shorttext (inside the error tag)?
You didn't specify the language you're using, i can give you the solution with PHP, the regex remain the same in every language anyway.
Here is the regex you're looking for :
#\<Error Code\=\"[0-9]+\" Type\=\"[0-9]+\" Status\=\"NotProcessed\" ShortText\=\"([a-z 0-9]+)\"\>#is
Concrete PHP use :
$yourOriginalString = '
<OTA_PingRQ>
<Errors>
<Error Code="101" Type="4" Status="NotProcessed" ShortText="Authentication refused">Authentication : login failed</Error>
</Errors>
</OTA_PingRQ>' ;
preg_match_all('#\<Error Code\=\"[0-9]+\" Type\=\"[0-9]+\" Status\=\"NotProcessed\" ShortText\=\"([a-z 0-9]+)\"\>#im', $yourOriginalString, $result) ;
print_r($result) ;
the regex function will return an array with :
[0] => Array
(
[0] => <Error Code="101" Type="4" Status="NotProcessed" ShortText="Authentication refused">
)
[1] => Array
(
[0] => Authentication refused
)
[0] is the full match
[1] list the content in the matching capturing groups : each () set in your regex
Some Regex explication :
Type\=\"[0-9]+\"
Assume "Type" can change and be any numbers.
ShortText\=\"([a-z 0-9]+)\"
Catch a string alphanumeric + space string. If you need some other stuffs, you can update like :
*[a-z 0-9\!\-]+*
catch ! and - too
#is
Are flags and ignore = caps and line break

postgresql regular expression for end of string

I'm trying to define a new domain for a status expressed into 1 or 2 characters. (Possible values are: {P,T,R,AR,V,AV})
I try the following:
> CREATE DOMAIN hbdt_estadosol CHAR(2) NOT NULL
> DEFAULT 'P'
> CHECK ( VALUE ~ '^(P|T|R|AR|V|AV)$' );
but when I try to insert a new value into a table using 'P' as the value, postgresql returns:
ERROR: value for domain hbdt_estadosol violates check constraint "hbdt_estadosol_check"
I got rid of the $ on '^(P|T|R|AR|V|AV)$' and the insert sentence works fine.
I try using \Z instead of $ and inset sentence sends violation again.
What is the right regular expression?
Thanks in advance

Replace pair of % in oracle

please, I have in Oracle table this texts (as 2 records)
"Sample text with replace parameter %1%"
"You reached 90% of your limit"
I need replace %1% with specific text from input parameter in Oracle Function. In fact, I can have more than just one replace parameters. I have also record with "Replace this %12% with real value"
This functionality I have programmed:
IF poc > 0 THEN
FOR i in 1 .. poc LOOP
p := get_param(mString => mbody);
mbody := replace(mbody,
'%' || p || '%', parameters(to_number(p, '99')));
END LOOP;
END IF;
But in this case I have problem with text number 2. This functionality trying replace "90%" also and I then I get this error:
ORA-06502: PL/SQL: numeric or value error: NULL index table key value
It's a possible to avoid try replace "90%"? Many thanks for advice.
Best regards
PS: Oracle version: 10g (OCI Version: 10.2)
Regular expressions can work here. Try the following and build them into your script.
SELECT REGEXP_REPLACE( 'Sample text with replace parameter %1%',
'\%[0-9]+\%',
'db_size' )
FROM DUAL
and
SELECT REGEXP_REPLACE( 'Sample text with replace parameter 1%',
'\%[0-9]+\%',
'db_size' )
FROM DUAL
The pattern is pretty simple; look for patterns where a '%' is followed by 1 or more numbers followed by a '%'.
The only issue here will be if you have more than one replacement to make in each string and each replacement is different. In that case you will need to loop round the string each time replacing the next parameter. To do this add the position and occurrence parameters to REGEXP_REPLACE after the replacement string, e.g.
REGEXP_REPLACE( 'Sample text with replace parameter %88888888888%','\%[0-9]+\%','db_size',0,1 )
You are getting the error because at parameters(to_number(p, '99')). Can you please check the value of p?
Also, if the p=90 then then REPLACE will not try to replace "90%". It will replace "%90%". How have you been sure that it's trying to replace "90%"?

OpenRefine custom text faceting

I have a column of names like:
Quaglia, Pietro Paolo
Bernard, of Clairvaux, Saint, or
.E., Calvin F.
Swingle, M Abate, Agostino, Assereto
Abati, Antonio
10-NA)\u, Ferraro, Giuseppe, ed, Biblioteca comunale ariostea. Mss. (Esteri
I want to make a Custom text facet with openrefine that mark as "true" the names with one comma and "false" all the others, so that I can work with those last (".E., Calvin F." is not a problem, I'll work with that later).
I'm trying using "Custom text facet" and this expression:
if(value.match(/([^,]+),([^,]+)/), "true", "false")
But the result is all false. What's the wrong part?
The expression you are using:
if(value.match(/([^,]+),([^,]+)/), "true", "false")
will always evaluate to false because the output of the 'match' function is either an array, or null. When evaluated by 'if' neither an array nor 'null' evaluate to true.
You can wrap the match function in a 'isNonBlank' or similar to get a boolean true/false, which would then cause the 'if' function to work as you want. However, once you have a boolean true/false result the 'if' becomes redundant as its only function is to turn the boolean true/false into string "true" or "false" - which won't make any difference to the values function of the custom text facet.
So:
isNonBlank(value.match(/([^,]+),([^,]+)/))
should give you the desired result using match
Instead of using 'match' you could use 'split' to split the string into an array using the comma as a split character. If you measure the length of the resulting array, it will give you the number of commas in the string (i.e. number of commas = length-1).
So your custom text facet expression becomes:
value.split(",").length()==2
This will give you true/false
If you want to break down the data based on the number of commas that appear, you could leave off the '==2' to get a facet which just gives you the length of the resulting array.
I would go with lookahead assertion to check if only 1 "," can find from the beginning until the end of line.
^(?=[^\,]+,[^\,]+$).*
https://regex101.com/r/iG4hX6/2

Xpath search for duplicate

I have the following xml:
<log>
<logentry revision="11956">
<author>avijendran</author>
<date>2013-05-20T10:25:19.678089Z</date>
<msg>
JIRA-1263 - did something
</msg>
</logentry>
<logentry revision="11956">
<author>avijendran</author>
<date>2013-05-20T10:25:19.678089Z</date>
<msg>
JIRA-1263 - did something 22 again
</msg>
</logentry>
</log>
I want to ignore any occurrence of the JIRA-1263 after the first one.
The xpath I am trying is (Which works if the duplicates nodes are following. But if you have duplicates else where(deep down), then it is ignored:
<xsl:variable name="uniqueList" select="//msg[not(normalize-space(substring-before(., '
')) = normalize-space(substring-before(following::msg, '
')))]" />
If you want to get each msg use //msg[starts-with(normalize-space(.), 'JIRA-1263')] to get output JIRA-1263 - did something and JIRA-1263 - did something 22 again.
And if you want to get any element with same codition use //*[starts-with(normalize-space(.), 'JIRA-1263')] which give same result as previous one.
At the end, if you want to get first msg with same condition use //logentry/msg[starts-with(normalize-space(.), 'JIRA-1263')][not(preceding::msg)] to get output JIRA-1263 - did something
You can define a key at the top level of your stylesheet that groups log entries by their first word:
<xsl:key name="logentryByCode" match="logentry"
use="substring-before(normalize-space(msg), ' ')" />
Now you need to select all logentry elements where either
the msg does not start JIRA-nnnn (where nnnn is a number) or
this entry is the first one whose msg starts with this word (i.e. the first occurrence of "JIRA-1234 - anything" for each ticket number)
(note that these two conditions need not be mutually exclusive):
<xsl:variable name="uniqueList" select="log/logentry[
(
not(
starts-with(normalize-space(msg), 'JIRA-') and
boolean(number(substring-before(substring(normalize-space(msg), 6), ' ')))
)
)
or
(
generate-id() = generate-id(key('logentryByCode',
substring-before(normalize-space(msg), ' '))[1])
)
]/msg" />
The boolean(number(...)) part checks whether a string of text can be parsed as a valid non-zero number (the text in this case being the part of the first word of the message that follows JIRA-), and the generate-id trick is a special case of the technique known as Muenchian grouping.
Equally, you could group the msg elements instead of the logentry elements, using match="msg" in the key definition and normalize-space(.) instead of normalize-space(msg).
And here another interpretation of what you try to do.
Find any first logentry which start with JIRA-XXXX.
If this it right try this:
log/logentry[
starts-with(normalize-space(msg), 'JIRA-') and
not
(
substring-before( normalize-space(msg), ' ')= substring-before( normalize-space(preceding::msg), ' ')
)]
This will find any logentry which starts with JIRA- but has not preceding one with the same substring before the first space (JIRA-XXXX) in your example.