Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Force" do in Uncrustify?

Many of the options include the Force value option:

Add or remove space between nested parens

sp_paren_paren { Ignore, Add, Remove, Force }

What does it mean? How is it different than Add?

like image 981
Brandon O'Rourke Avatar asked Jan 03 '12 21:01

Brandon O'Rourke


3 Answers

Add means "add if not already present", meaning that if something's already there, leave it (and the formatting alone). Force means add if not present, and reformat if it is present:

// Original
if (cond)         {
    func();
}

// Add curly braces (already present, leaves formatting alone)
if (cond)         {
    func();
}

// Force curly braces
if (cond) {
    func();
}

Or another example:

// Original
if (cond)
    func();

// Add curly braces
if (cond) {
    func();
}

// Force curly braces (behaves just like add in this case)
if (cond) {
    func();
}
like image 192
Chris Eberle Avatar answered Nov 19 '22 08:11

Chris Eberle


Add adds if it is not there.

Remove removes if it is there.

Force does a remove then an add.

like image 29
edwinc Avatar answered Nov 19 '22 10:11

edwinc


As "Add or remove X between A and B"

Add: only adds a X when there is no X appeared

AB -> AXB
AXB -> AXB
AXXB -> AXXB

Remove: removes all appeared X

AB -> AB
AXB -> AB
AXXB -> AB

Force: as edwinc said Remove then Add -> Removes all (any) X first and adds a X finally

AB -> AXB
AXB -> AB -> AXB
AXXB -> AB -> AXB

But sometimes 'add X' may be defined as add some number X elsewhere, so Force will like a "reformat" as Chris said.

like image 3
ob.yann Avatar answered Nov 19 '22 09:11

ob.yann