Can we do case insensitive comparison in nxbre's if element - case-insensitive

I am using NxBre 3.2.0. I want to compare two strings in case insensitive manner but did not find any option in IF element. Is it possible to do so.

I supposed you're using the Flow Engine since you mentionned If.
To perform a case insensitive comparison use the ObjectLookup element to call statically String.Compare(left,right,true), then test the result to be equal to 0.
See: http://msdn.microsoft.com/en-us/library/zkcaxw5y%28v=vs.110%29.aspx

Related

ICU: simple case mapping for whole strings

I would like to find a substring in UTF-8 string, case-insensitive. from what I read, the usual way it's done is case folding the strings in order to bring them to canonical form.
However, since case folding can change the length of the strings (and I don't want to change the length of the strings because I need to know what is the exact offset of the substring match in the original string), it seems I should be using Simple case mapping. although the case-insensitive comparison won't be accurate, it will be best effort.
However, I cannot find in ICU API functions that operate on strings with Simple case mapping. I can find Simple case mapping only for single char functions (u_foldCase() in uchar.h). Is there an option to use Simple case folding for whole strings?

How to create a program that identifies longest substring palindrome regardless of letter casing

I've attempted at googling algorithms for a program that outputs the result indicated in the question. Mostly, all what I've found was algorithms that satisfied the first constraint, but did not take into account the second part (ignoring the casing of letters). Conventional functions, such as strcmpi (I'm using c++) requires constant characters which make it impossible to incorporate within the algorithms alluded to above. In essence, I just need an idea on how I can go about creating such a program.
First create a program that identifies longest substring palindrome using your own compare function. And in that compare function if two characters are same then return true else if the difference between ASCII values of two characters is 32 then also return true. And rest as it is.

Best way to mask dynamic data (timestamps) using ScalaTest

I'm using ScalaTest for my unit testing. I have a test result (JSON) that might look like below. The actual result is huge and complex. This is an example.
[{"name":"George", "when":143828333, ...}, {"name":"Fred", "when":14857777, ... }]
The 'when' field values are dynamic and will change from test-to-test (i.e. current timestamp), so I can't test against these. I could use some regex to mask these out, basically replacing them with some inert token.
Does ScalaTest have an more elegant way of handling dynamic bits of data like this?
You can make a custom Equality for the types you're comparing. Your custom Equality can ignore the dynamic fields for the equality comparison. Info on Equality is here:
http://doc.scalatest.org/2.2.0/index.html#org.scalactic.Equality
All you need to do is define the areEqual method and then make it implicit. So Equality[JsonType] or Equality[String], whatever the type is. This will then be picked up by the === operator and the equal matcher in your assertions.
What I've done many times in the past in this situation is exactly what you propose: use a regex to replace the dates with a constant so your comparisons will work.

How Switch case Statement Implemented or works internally?

I read somewhere that the switch statement uses "Binary Search" or some sorting techniques to exactly choose the correct case and this increases its performance compared to else-if ladder.
And also if we give the case in order does the switch work faster? is it so? Can you add your valuable suggestions on this?
We discussed here about the same and planned to post as a question.
It's actually up to the compiler how a switch statement is realized in code.
However, my understanding is that when it's suitable (that is, relatively dense cases), a jump table is used.
That would mean that something like:
switch(i) {
case 0: doZero(); break;
case 1: doOne();
case 2: doTwo(); break;
default: doDefault();
}
Would end up getting compiled to something like (horrible pseudo-assembler, but it should be clear, I hope).
load i into REG
compare REG to 2
if greater, jmp to DEFAULT
compare REG to 0
if less jmp to DEFAULT
jmp to table[REG]
data table
ZERO
ONE
TWO
end data
ZERO: call doZero
jmp END
ONE: call doOne
TWO: call doTwo
jmp END
DEFAULT: call doDefault
END:
If that's not the case, there are other possible implementations that allow for some extent of "better than a a sequence of conditionals".
How swtich is implemented depends on what values you have. For values that are close in range, the compiler will generally generate a jump table. If the values are far apart, it will generate a linked branch, using something like a binary search to find the right value.
The order of the switch statements as such doesn't matter, it will do the same thing whether you have the order in ascending, descending or random order - do what makes most sense with regard to what you want to do.
If nothing else, switch is usually a lot easier to read than an if-else sequence.
On some googling I found some interestin link and planned to post as an answer to my question.
http://www.codeproject.com/Articles/100473/Something-You-May-Not-Know-About-the-Switch-Statem
Comments are welcome..
Although it can be implemented as several ways it depends on how the language designer wants to implement it.
One possible efficient way is to use Hash Maps
Map every condition (usually integer) to the corresponding expression to be evaluated followed by a jump statement.
Other solutions also might work as often switch has finite conditions but a efficient solution shall be to use Hash map

Most Efficient way to 'look up' Keywords

Alright so I am writing a function as part of a lexical analyzer that 'looks up' or searches for a match with a keyword. My lexer catches all the obvious tokens such as single and multi character operators (+ - * / > < = == etc) (also comments and whitespace are already taken out) so I call a function after I've collected a stream of only alphanumeric characters (including underscores) into a string, this string then needs to be matched as either a known keyword or an identifier.
So I was wondering how I might go about identifying it? I know I basically need to compare it to some list or array or something of all the built in keywords, and if it matches one return that match to it's corresponding enum value; otherwise, if there is no match, then it must be a function or variable identifier. So how should I look for matches? I read somewhere that something called a Binary Search Tree is an efficient way to do it or by using Hash Tables, problem is I've never used either so I am not sure if it's the right way. Could I possibly use a MySQL database?
If your set of keywords is fixed, a perfect hash can be built for O(1) lookup. Check out gperf or cmph.
A "trie" will surely be the most efficient way.
Whatever implementation of std::map you have will probably be sufficient.
This is for a language, with a specific set of keywords that never change, and there aren't very many of them?
If so, it probably doesn't matter what you use. You will have bigger fish to fry.
However, since the list doesn't change, it would be hard to beat a hard coded search like this:
// search on first letter
switch(s[0]){
case 'a':
// search on 2nd letter, etc.
break;
case 'b':
// search on 2nd letter, etc.
break;
........
case '_':
// search on 2nd letter, etc.
break;
}
For singe character keywords a lookup table would be perfect. For multicharacter (especially if the lengths differs): a hash table. If you need performance, you could even use source code generation to create the hash tables (using a simple hash function that is able or not to ignore case, depending on your syntax).
So I'd implement it with a LUT and a hash table: first you check the first character with the LUT (if it's a simple operator, it would start with a non-alpha-numeric value), and, if not found, check the hash table.