I'm currently documenting a C code which is not from me.
Either than commenting the code, and then making blocks for Doxygen documentation, I prefer to put comments after each line of code (with ///) in order to implement directly everything in Doxygen.
So far it works very well but I'm not able to generate lists and paragraphs. It seams that list and paragraph are reinitialized each time I start a new comment on next line with ///
Is there something I am missing ?
[EDIT] : an exemple :
So this works perfectly fine, if I put it before my function :
/**
* 1. Title 1. \n
* Description 1. \n
* More description \n
* - Subtitle1. \n
* - Subtitle2. \n
* Description of subtitle2 \n
* 2. Title 2. \n
* Description 2.
*/
But this don't work at all, if I put it INSIDE my function :
Some code /// 1. Title 1. \n
other code /// Description 1. \n
x=x /// More description \n
y=x /// - Subtitle1. \n
code /// - Subtitle2. \n
code /// Description of subtitle2 \n
code /// 2. Title 2. \n
code /// Description 2.
It behaves like if each line was a new comment block.
Thank you,
Related
Is there an easy way to add spaces to multiple lines so that each line has equal amount of characters?
Motivation, say I want to add '*' at end of each line
/***************************
* This is line 1. *
* Line2. *
* May be line3. *
* For sure this is line 4. *
****************************/
Without using any custom format program, is there a way in VS code to add different number of spaces just before the last '*' like so:
/***************************
* This is line 1. *
* Line2 *
* May be line3 *
* For sure this is line 4. *
****************************/
select all the * at the lines that are incorrect
add as much spaces as needed to get all *'s beyond the correct position
Esc to get out of multi cursor
Place Multi Cursor on all lines at the position where you want the *'s
press Ctrl+Delete
Esc to get out of multi cursor
You can do this fairly simply with an extension I wrote, Find and Transform, because it allows you to use javascript or the vscode extension api in a replacement. So starting with this text:
/***************************
* This is line 1.
* Line2.
* May be line3.
* For sure this is line 4.
****************************/
you would make this keybinding (in your keybindings.json):
{
"key": "alt+q", // whatever keybinding you want
"command": "findInCurrentFile",
"args": {
"replace": [
"$${",
"const str = `${selectedText}`;", // get the selected text
// since the selected text can contain newlines, surround the variable with backticks
"let lineArray = str.split('\\n');", // newlines must be double-escaped
"let firstLineLength = lineArray[0].length;",
"lineArray = lineArray.map((line, index) => {",
"if (index === 0) return line;",
"else if (line === lineArray.at(lineArray.length-1)) return line;",
"else return `${line.padEnd(firstLineLength-1, ' ')}*`;",
"});",
"return lineArray.join('\\n');",
"}$$"
]
}
}
So the replacement is straightforward javascript which gets the selected text, splits it on the newlines and then uses the length of the first line to pad the other lines with spaces and then adds a * to the end of each line. It does nothing to the first or last line of the selection.
Demo:
You can do multiple selections at a time too.
I would like to define a snippet for comments like
//************
//* foo A1 *
//************
where I enter foo A1 and it would create a line with (6+ len(${1}) asterisks etc. - is that doable and if so, how?
While I am a big proponent of HyperSnips (see
[VSCODE]: Is there a way to insert N times the same characters,
VS Code: how to make a python snippet that after string or expression hitting tab will transform it and
VSCode Advanced Custom Snippets for how to use it),
it is instructive to see how to do this with just the built-in snippet functionality in vscode. Here is a snippet that does what you want:
"Custom Comment": {
"prefix": ["cc2"], // whatever trigger you want, then tab, write your info and tab again
"body": [
"//***${1/./*/g}***",
"//* $1 *",
"//***${1/./*/g}***"
]
},
That just adds 3 asterisks to the beginning and 3 to the end of your added comment, each character of which is replaced by an asterisk as well.
You can use the extension HyperSnips
snippet comment "Comment" A
``rv = '//' + '*'.repeat(t[0].length + 6)``
//* $1 *
``rv = '//' + '*'.repeat(t[0].length + 6)``
endsnippet
Documentation on Swift provides the following code for spacing Examples in Markup:
/*:
- example: *A simple `for` loop.*\
This example shows a `for` loop that prints the numbers 1 to 5.\
\
`for index in 1...5 {`\
` print("index = \(index)")`\
`}`}
*/
In rendered Markup no spaces appear:
How do you put spaces in code snippets, especially examples with custom callouts(), in Markup?
So to show the spaces in your code example try to do it like that regarding to your example:
/*:
A simple for loop.\
This example shows a for loop that prints the numbers 1 to 5.
for index in 1...5 {
print("index = \(index)")
}
*/
Result looks in Rendered Markup like this (the spaces appear in the code block):
Edit after comment:
The only way I found out, so that your first two lines of Markup are also inside of the example and also to simulate spaces is to use this code (in the line of the print, first two backquotes and between them one space, then after that eight spaces until the opening backquote of the print):
/*:
- example: *A simple `for` loop.*\
This example shows a `for` loop that prints the numbers 1 to 5.\
\
`for index in 1...5 {`\
` ` `print("index = \(index)")`\
`}`}
*/
This results to:
I have an XML file in a QByteArray I am using the indexOf method to find a string in the array, but the position returned isn't correct. If I examine the data content using qDebug I can see that the data has escape characters which isn't a problem but I don't think indexOf is counting the escape characters.
For example the result from:
qDebug() << arybytXML;
A snippet from the result of this is:
<?xml version="1.0" encoding="utf-8"?><!--\n Node: gui\n Attrbuttes: left, right, top and bottom defines the pixel white space to allow\n from the edge of the display\n\t\tlanguage, should be set to the appropriate country code, an XML file named using\n\t\tthe country code must exist, e.g. 44.xml\n//-->\n<gui id=\"root\" bottom=\"0\" left=\"0\" right=\"0\" top=\"24\" language=\"44\">
I use the code:
intOpenComment = arybytXML.indexOf("<!--");
The result is that intOpenComment is 39. If I then search for the end comment and try to extract the data I get the wrong result:
intClosingComment = arybytXML.indexOf("-->", intOpenComment);
QString strComment = arybytXML.mid(intOpenComment
,intClosingComment + strlen("-->"));
Result:
<!--\n Node: gui\n Attrbuttes: left, right, top and bottom defines the pixel white space to allow\n from the edge of the display\n\t\tlanguage, should be set to the appropriate country code, an XML file named using\n\t\tthe country code must exist, e.g. 44.xml\n//-->\n<gui id=\"root\" bottom=\"0\" left=\"0\" rig"
The result should stop after -->, why is there more data?
The problem is that when using mid, the 2nd parameter should be the number of bytes and needed to have 'intOpenComment' removed.
I am trying to extract a substring out of some html code in wxWidgets but I can't get my method working properly.
content of to_parse:
[HTML CODE]
<html><head></head><body><font face="Segue UI" size=2 .....<font face="Segoe UI"size="2" color="#000FFF"><font face="#DFKai-SB" ... <b><u> the text </u></b></font></font></font></body></html>
[/HTML CODE] (sorry about the format)
wxString to_parse = SOStream.GetString();
size_t spos = to_parse.find_last_of("<font face=",wxString::npos);
size_t epos = to_parse.find_first_of("</font>",wxString::npos);
wxString retstring(to_parse.Mid(spos,epos));
wxMessageBox(retstring); // Output: always ---> tml>
As there are several font face tags in the HTML the to_parse variable I would like to find the postion of the last <"font face= and the postion of the first <"/font>" close tag.
For some reason, only get the same to me unexpected output tml>
Can anyone spot the reason why?
The methods find_{last,first}_of() don't do what you seem to think they do, they behave in the same way as std::basic_string<> methods of the same name and find the first (or last) character of the string you pass to them, see the documentation.
If you want to search for a substring, use find().
Thank you for the answer. Yes you were right, I must have somehow been under the impression that Substring() / substr() / Mid() takes two wxStrings as parameters, which isn't the case.
wxString to_parse = SOStream.GetString();
to_parse = to_parse.Mid(to_parse.find("<p ")); disregarts everything before "<p "
to_parse = to_parse.Remove(to_parse.find("</p>")); removes everything after "</p>"
wxMessageBox(to_parse); // so we are left with everything between "<p" and "</p>"