Format multiline comments with AStyle - astyle

Is there a way to format multiline comments with AStyle? For example force comment blocks to maximum length of 80 characters.

Related

How to include a multiline text in regex pattern

I have a pattern ^[0-9]+$, but I want it to include a \n new-line symbol so that the string like below would be valid:
123\n345\n678\n9752\n or in other words:
123
345
678
9752
Assuming you don't want to include leading/trailing newlines, try:
\A[0-9]+(?:\n[0-9]+)*\Z
See an online demo.
\A - Start-string anchor;
[0-9]+ - 1+ digits;
(?:\n[0-9]+)* - Match nested non-capture group 0+ times validating a single newline character and 1+ digits;
\Z - End-string anchor.
Note: As per my comments, ^[0-9]+(?:\n[0-9]+)*$ would also work with the right flags turned on/off.

How to limit simple form input to 50 characters

Is it possible to limit a simple form input to only 50 characters without javascript?
I have used the max_length attribute, however this includes blank spaces which is not what i want.
I've attempted to use pattern (as suggested on another post), but i can't seem to get that to work either.
Thanks
I don't know why you don't want it to include blanks.
Usually I use max_length including blanks and leave it to the user to trim their excess whitespace. I'm not disagreeing, I honestly don't know what your requirement is.
If you want to allow leading and trailing whitespace, but are willing to leave it to the user to replace excess whitespace within the text to one whitespace character then this is the pattern you want:
<input pattern="^\s*.{0,50}\s*$">
Sometimes for multiline regular expressions, \A is used instead of ^ and \z is used instead of $, but I'm not sure HTML supports that in their regular expressions.

python3 textwrap unexpected output on json format?

>>> a = '{"key1": "aaaaaaaaaaaaaaaaa", "key2": "bbbbbbbbbbbbbbbbbbbbbbbb"}'
>>> len(a)
64
>>> textwrap.wrap(a, 32, drop_whitespace=False)
['{"key1": "aaaaaaaaaaaaaaaaa", ', '"key2": ', '"bbbbbbbbbbbbbbbbbbbbbbb"}']
I was expecting
['{"key1": "aaaaaaaaaaaaaaaaa", "k', 'ey2": "bbbbbbbbbbbbbbbbbbbbbbb"}']
I'am missing something ?
Your expectation is wrong, according to the official documentation:
Wraps the single paragraph in text (a string) so every line is at most width characters long. Returns a list of output lines, without final newlines.
[...]
Text is preferably wrapped on whitespaces and right after the hyphens in hyphenated words; only then will long words be broken if necessary, unless TextWrapper.break_long_words is set to false.
Your expected output is literally broken off after 32 characters, whereas the actual output is split into segments of 30, 8, and 27 characters long – broken only on the whitespace characters in the original string.
The second segment is much shorter than the others because the first string plus this next non-whitespace run "key2": is longer than 32 characters, and this short run plus the next phrase is also longer than 32 characters. Only when there is absolutely no possibility to break on a space or hyphen, a break in the middle of a non-whitespace run will occur.

Pure HTML input type text validation using pattern

Recently I tried alot but I still unable to figure how should I able to validation for my text field. I hope I can get some help from here, my questions is I want to validate input text field only accept A-Z a-z 0-9 and space within word. And at least one char or number.
For example, "abc def" , "abc092", "abcdef"
Only in HTML input tag element .
I tried this
but this pattern unable to fullfil my requirements.
the pattern i want to achieve is
1) abc def
2) abcdef
3) abc123
4) a1b2c3 d4e5
5) allow to have empty space within words
the pattern i dont want to accept is
1) empty string
2) no alot of whitespace at the begining or end of the string
3) no bracket and etc special characters
Try
<input type="text" pattern="^\w+([\w ]*\w)*$">
Basically the break down is this:
\w+ - Select a word character ("A-z0-9") one or more times
()* - Select what's in here 0 or more times, which is
[\w ]*\w - Select a word character or space one or more times followed by another word character
No leading or trailing white space allowed. Only word characters allowed and internal spaces.
For some unit tests and breakdown of the regex see: https://regex101.com/r/7UnL9J/1
You can use the Pattern attribute with regex but it is supported only in HTML 5.
Like this " id="username" pattern="[A-Za-z0-9]+"
Check the below link for more information
https://html.com/attributes/input-pattern/#Username_Patterns
Have you tried this?
<input type="text" pattern="[a-zA-Z0-9\s]+">

special chars generated when using HTML::TreeBuilder & HTML::Element

I've two questions:
If I take out any text using text() or as_trimmed_text() function and want to push in some element then do I need to use HTML::Entities::encode_entities? :
my $text=$node->as_trimmed_text();
$a->push_content($text); # Do I need to use encode_entities here?
Secondly after processing and generating whole html document using as_HTML() it's sometimes generating some special characters for example: Â(Â) as an extra char when all I see is single space in Dreamweaver.
I have two answers:
Assuming that you want the content of $a to be the same as the content of $node, you do not need to encode_entities as push_content inserts the passed string as a text node rather than parsing it as markup. OTOH, if the content of $node is <span> (represented in HTML source as <span>) and you actually want $a to display <span> (represented in HTML source as &lt;span&gt;), you would call encode_entities on it.
Chances are that your input text contains raw UTF-8 characters which the code is interpreting as Latin-1 or a similar encoding. The "single space" characters are actually U+00A0, non-breaking space, which is represented in UTF-8 by the two bytes 0xc2 0xa0, which when interpreted in Latin-1 are "Â" and non-breaking space.