What does "Force" do in Uncrustify?
Asked Answered
H

3

42

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?

Happ answered 3/1, 2012 at 21:10 Comment(0)
S
47

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();
}
Slovene answered 3/1, 2012 at 21:15 Comment(0)
C
11

Add adds if it is not there.

Remove removes if it is there.

Force does a remove then an add.

Commissary answered 15/8, 2013 at 4:39 Comment(0)
F
3

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.

Fannie answered 4/2, 2015 at 8:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.