place else on new line in Visual Studio Code - c++

how can I place my else on new line, for example, I want to change
if () {
} else {
}
into
if() {
}
else {
}
I have edit theC_Cpp: Clang_format_fallback Style and entered { BasedOnStyle:Microsoft, IndentWidth: 4, ColumnLimit: 0}

Looks like vscode's formatter uses clang-format by default, so if you didn't change it, we can refer to the clang-format options directly, can you try to append the following key-value (BeforeElse) pair within your braces?
BraceWrapping: [BeforeElse: true]
If that doesn't work, then you should try to use the traditional .clang-format file which vscode also supports.

Related

Reading multiple files from FileChooserDialog GTK 3

I am trying to open a Gtkmm::FileChooserDialog to choose multiple files and print their paths along with filenames to a label. I can open the dialog and choose the files but I am having a hard time reading the filenames to my variables.
FileChooserDialog openFileDialog("", FILE_CHOOSER_ACTION_OPEN);
openFileDialog.add_button("Cancel", RESPONSE_CANCEL);
openFileDialog.add_button("Open", RESPONSE_OK);
openFileDialog.set_current_folder(ustring::compose("%1/Desktop", ustring(getenv("HOME"))));
openFileDialog.set_transient_for(*this);
openFileDialog.set_select_multiple(true);
Glib::RefPtr<Gtk::FileFilter> fileFilter = Gtk::FileFilter::create();
fileFilter->set_name("Text Files (*.txt)");
fileFilter->add_pattern("*.txt");
openFileDialog.add_filter(fileFilter);
fileFilter = Gtk::FileFilter::create();
fileFilter->set_name("All Files (*.*)");
fileFilter->add_pattern("*.*");
openFileDialog.add_filter(fileFilter);
if (openFileDialog.run() == RESPONSE_OK)
label.set_text(ustring::compose("File = %1", ustring(openFileDialog.get_filename())));
return true;
You can use Gtk::FileChooser::get_filenames (Gtkmm 3.24):
if (openFileDialog.run() == Gtk::RESPONSE_OK)
{
for(const auto& fileName : openFileDialog.get_filenames())
{
label.set_text(Glib::ustring::compose("File = %1", Glib::ustring(fileName)));
}
}
which returns a std::vector of file names.
Note: In my answer, I keep overwriting the label variable because it was all the context there was in your code snippet. My be you have multiple labels or you want to pack all the file names somehow in a single label. I let this part to you.

what is the correct map with regexp in nginx?

I want to use different builds depends of browser version and device.
For example in "mobile chrome/80+ version" I need to have modern-bundle and on lower versions - legacy-bundle. Bur modern version for desktop is lower than for mobile: "chrome/70+ version" must have modern-bundle and on lower than 70 - legacy-bundle
I tried this code with two maps but finally I always have legacy-bundle instead of modern-bundle
What's wrong there?
map $http_user_request $is_mobile {
default false;
"~*Mobile" true;
}
map "$http_user_request:$is_mobile" $modern_browser {
default "";
"~Chrome\/([8-9][0-9]|\d{3,})\.:true" "modern-bundle";
"~Chrome\/([7-9][0-9]|\d{3,})\.:false" "modern-bundle";
}
I found the answer for my question. Just needed to add one more variable to map
map $http_user_request $is_mobile {
default false;
"~Mobile" true;
}
map "$http_user_request:$is_mobile:$http_user_request" $modern_browser {
default "";
"~Chrome\/([8-9][0-9]|\d{3,})\..*:true:" "modern-bundle";
"~Chrome\/([7-9][0-9]|\d{3,})\..*:false:" "modern-bundle";
}

Remove line break after single-statement if with clang-format

I am trying to get clang-format to leave if-statements with one statement on the same line.
Example input:
if(is_finished) break;
if(foo) {
// do something
}
clang-format output:
if(is_finished)
break;
if(foo) {
// do something
}
Wanted output:
if(is_finished) break;
if(foo) {
// do something
}
None of the space related options seem to match this style.
current config:
---
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: ForIndentation
SpaceBeforeParens: Never
BraceWrapping:
AfterControlStatement: false
The relevant config option is AllowShortIfStatementsOnASingleLine.
The choices are:
Never
WithoutElse
Always
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
AllowShortIfStatementsOnASingleLine
And
AllowShortBlocksOnASingleLine
The first one does what you want, AllowShortBlocksOnASingleLine will also allow code such as
if (expression) { Something(); }

Put a quotes around current list item in a SASS loop

I have this on Friday evening which I've stacked with. Trying to add quotes around the current item $breakpoint and produce output like
a[data-x="bp1"]
a[data-x="bp2"]
... and so on
but instead, as you guess I'm having a[data-x=bp2]
$spacings: "8%", "9%", "10%", "11%", "13%", "14%";
#each $breakpoint in $breakpoints {
a[data-x=#{$breakpoint}] {
.span {
margin-left: nth($spacings, index($breakpoints, $breakpoint));
}
}
}
any help will be highly appreciated!
You need to escape your quotation marks with \ to keep them in the compiled CSS.
You can either write the names of your breakpoints as:
$breakpoints: "\"bp1\"", "\"bp2\"", "\"bp3\"", "\"bp4\"", ...;
Or simply write your selector as a[data-x=#{"\"#{$breakpoint}\""}]:
$spacings: "8%", "9%", "10%", "11%", "13%", "14%";
$breakpoints: bp1, bp2, bp3, bp4, pb5, bp6; // Quotation marks not needed
#each $breakpoint in $breakpoints {
a[data-x=#{"\"#{$breakpoint}\""}] {
.span {
margin-left: nth($spacings, index($breakpoints, $breakpoint));
}
}
}
Another solution is to use single quotations marks around your variable (or breakpoints names) and then unquote():
a[data-x=#{unquote('"#{ $breakpoint }"')}]

CouchDB: View to return only certain documents?

I have (tried) to write a view to identify documents with an "otherCauseForRelease" attribute AND that attribute is actually populated. My View code is:
function (doc) {
if(doc.payload.otherCauseForRelease.length > 5); emit(doc.payload.otherCauseForRelease);
}
However, the return set includes documents with attribute values like "" (an open double-quotation followed by a close double-quotation). How can I exclude these documents from my results?
Try with this one here :
function (doc) {
if(doc.payload.otherCauseForRelease.length > 5)
emit(doc.payload.otherCauseForRelease);
}
You basically add an extra ; at the end of your if. Doing so, it didn't consider the next statement as the body of the if.
Another example with curly braces:
function (doc) {
if(doc.payload.otherCauseForRelease.length > 5){
emit(doc.payload.otherCauseForRelease);
}
}