How to create a parser which is a whitespace but not a line separator, in PetitParser? - whitespace

There is a built-in whitespace() parser in PetitParserDart, which checks character in:
(9 <= value && value <= 13) || (value == 32) || (value == 160)
|| (value == 5760) || (value == 6158) || (8192 <= value && value <= 8202) || (value == 8232)
|| (value == 8233) || (value == 8239) || (value == 8287) || (value == 12288)
Now I want a custom whitespace parser that is a whitespace() parser, but not accept line separator \n.
How to do that, I don't want to copy and modify the code inside whitespace(). Is there a better way to do this?

There are various ways to do this.
One way that reuses the existing parser would be:
char('\n').not().seq(whitespace()).pick(1);
Another way is to create a new character pattern:
pattern('\t\f\r ');
This does not exactly match all the unicode whitespaces that whitespace() accepts, but likely is enough for most use-cases. Alternatively you can add the unicode ranges as well:
pattern('\t\f\r \u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000');

Related

Ignore part of the linq query if variable equals a specific value

var longlinq = viewModel.Where(x => (x.Systems.Storage == SelectOption || x.Systems.Laptop == SelectOption ||
x.Systems._2In1 == SelectOption ||
x.Systems.Convertible == SelectOption )
||
(x.Component.Components == SelectOptionComp ||
x.Component.Boards == SelectOptionComp)
||
( x.Service.Services == SelectOptionSer ||
x.Service.DevelopmentTools_andServices == SelectOptionSer )
||
(x.Software.Softwares == SelectOptionSoft ||
x.Software.Analytics == SelectOptionSoft)
||
(x.Application.Applications == SelectOptionApp ||
x.Application.PrintImaging_andOfficeAutomation ));
Let me explain my question with an example:
For instance SelectOptionComp equals "-", then I want to ignore the parts where I used
SelectOptionComp in longlinq or set SelectOptionComp to " " in the longlinq.
I don't want to use ifs because of large number of combinations.
How do I do that?
I have used ternary operator Use the ternary operator: (SelectOptionComp == "-" ? true : (x.Component.Components == SelectOptionComp || x.Component.Boards == SelectOptionComp))

Primeng table - column sort with special character

I have a primeng table my column values are as follows which are displayed as string. They contain a special character(√); Some values contain special character and some wont'
I want to sort them as numbers so that it sorts properly by excluding the special character(√). Is there any way to implement custom sort.
√22.76
√-1.11
√-4.40
4.77
-2.0
√-11.23
√4.5
√6.7
You can use sortFunction and the property customSort.
You need to set sortFunction with the function that will handle your custom logic (and handle the specific character)
You need to set customSort to true. If you don't, the default sort would be used.
Template example
<p-table [value]="products3" (sortFunction)="customSort($event)" [customSort]="true">
<!-- ... -->
</p-table>
Typescript part example
customSort(event: SortEvent) {
event.data.sort((data1, data2) => {
let value1 = data1[event.field];
let value2 = data2[event.field];
let result = null;
if (value1 == null && value2 != null)
result = -1;
else if (value1 != null && value2 == null)
result = 1;
else if (value1 == null && value2 == null)
result = 0;
else if (typeof value1 === 'string' && typeof value2 === 'string')
result = value1.localeCompare(value2);
else
result = (value1 < value2) ? -1 : (value1 > value2) ? 1 : 0;
return (event.order * result);
});
}
In your typescript part, you can handle your symbol to compare as you wish.
Source documentation of the sort and custom sort

Thymeleaf #aggregates.sum with multiple conditions

I have a list of MyObject as below
List<MyObject> myObjList;
where MyObject is class defined as below
public class MyObject{
private String status;
private double amount;
}
Now i want to get sum of amount from the list only if amount is not null and if status code is neither XX or YY
I know i can do this on java, but i need to do this on thymeleaf and this is what i tried but it is not working
aggregates.sum(myObjList.?[amount!= null && (status!='XX' || status!='YY')].![amount])
I am not getting any error. I am not sure what am I doing wrong here.
What does not working mean? You are getting the wrong number? Regardless, your boolean expression is incorrect. The expression reads (status != 'XX' || status != 'YY'), which will match all records.
For example, if status = 'XX' then:
('XX' != 'XX' || 'XX' != 'YY') => (false OR true) => true
The same thing happens for YY:
('YY' != 'XX' || 'YY' != 'YY') => (true OR false) => true
Other than that, everything seems to be working for me. Corrected expression (parens for status not needed, unless you think it reads better):
${#aggregates.sum(myObjList.?[amount != null && (status != 'XX' && status!='YY')].![amount])}

Unable to hide handsontable column header when i use td.hidden = true; cell render

I have used the following custom column render code for hiding handsontable column
function getCustomRenderer() {
return function(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if (colsToHide.indexOf(col) > -1) {
td.hidden = true;
} else {
td.hidden = false;
}
}
but when i set colHeaders: true, the column headers does not get hidden.
http://jsfiddle.net/LkLkd405/91/
Correct, you can't hide the column headers that way since the rendering happens independently of the column renderers. I will go ahead and assume your endgoal is to put in data into your data object that you would like to hide, like a database ID. The solution is to use the columns definition.
This option, if you read the documentation carefully, allows you to define which columns to show. So, for example, if you had 3 columns plus your ID column, you would have:
var colHeaders = ['col1', 'col2', 'col3', 'ID'];
// assume `dataArray` is an aray you previously defined, with row Objects with 4 keys each, corresponding to the first 3 real data columns and the fourth as the ID.
columns: [{
data: colHeaders[0],
type: 'text'
},{
data: colHeaders[1],
type: 'text'
},{
data: colHeaders[2],
type: 'text'
}]
Now you don't even need to have a custom renderer as the table will omit that fourth value.
hot.addHook('afterGetColHeader', RemoveUnWantedHeader);
function RemoveUnWantedHeader(col, th) {
if (th.textContent == "A" || th.textContent == "B" || th.textContent == "C"
|| th.textContent == "D" || th.textContent == "E"
|| th.textContent == "F" || th.textContent == "G" || th.textContent == "H"
|| th.textContent == "I" || th.textContent == "J"
|| th.textContent == "K" || th.textContent == "L" || th.textContent == "M"
|| th.textContent == "N" || th.textContent == "O"
|| th.textContent == "P" || th.textContent == "Q" || th.textContent == "R"
|| th.textContent == "S" || th.textContent == "T"
|| th.textContent == "U" || th.textContent == "V" || th.textContent == "W"
|| th.textContent == "X" || th.textContent == "Y" || th.textContent == "Z"
|| th.textContent == "AQ" || th.textContent == "AR" || th.textContent == "AS"
|| th.textContent == "AT" || th.textContent == "AU" || th.textContent == "AV" || th.textContent == "AW") {
th.style.display = 'none';
}
}
I have used hook to remove the headers I need to. I tried the same inside my HandsonTable it doesn't work so I tried the same using addHook and worked like charm.
afterGetColHeader: It is a function which will be rendered when header is called.
RemoveUnWantedHeader: It is my own callback. You can have your own conditions and can remove.
Reference: Handsontable Add Hooks

LINQ to Entities grouped logical operations in Where

I'm trying to execute the following linq query and it seems to be ignoring order of operations. (Parentheses first)
var result = _repo.Transactions.Where(t =>
t.DateEntered > EntityFunctions.AddDays(DateTime.Now, -7)
&& ( t.TranDesc != "BALANCE FORWARD" && t.Withdrawl == 0 && t.Deposit == 0 ) );
Here's the where clause that generates:
WHERE ([Extent1].[dateentered] > (DATEADD (day, -7, SysDateTime())))
AND (N'BALANCE FORWARD' <> [Extent1].[TranDesc])
AND (cast(0 as decimal(18)) = [Extent1].[Withdrawl])
AND (cast(0 as decimal(18)) = [Extent1].[Deposit])
Any ideas what I'm doing wrong?
EDIT:
This is actually what I wanted and it solved my problem. Just didn't think it all the way though. Thanks.
var result = _repo.Transactions.Where(t =>
t.dateentered > EntityFunctions.AddDays(DateTime.Now, -7)
&& ((t.TranDesc == "BALANCE FORWARD" && (t.Withdrawl != 0 || t.Deposit != 0))
|| (t.TranDesc != "BALANCE FORWARD")));
There is no difference between a && (b && c && d) and a && b && c && d, and that's why parentheses within generated SQL are not exactly the same as in your LINQ query. But at the end there is no difference between these queries.

Resources