Compare commits

..
62 Commits
Author SHA1 Message Date
saalen 3524d66639 #42 fix recognition of Java/C# multi line strings 2024-06-05 14:42:43 +02:00
saalen 3f3f90b577 updated version number 2024-06-04 16:27:41 +02:00
saalen af17f3b833 https://sourceforge.net/p/astyle/bugs/571 add option --pad-negation=before 2024-06-04 16:16:23 +02:00
saalen 88a2903caf https://sourceforge.net/p/astyle/bugs/571 add option --pad-negation in bash completion 2024-06-03 16:22:35 +02:00
saalen 4154588caf https://sourceforge.net/p/astyle/bugs/571 add option --pad-negation in help messages 2024-06-03 16:18:34 +02:00
saalen 9369c8455f https://sourceforge.net/p/astyle/bugs/571 add option --pad-negation 2024-06-03 15:27:10 +02:00
saalen aa7e2febec https://sourceforge.net/p/astyle/bugs/573/ apply align-pointer=type only if type is present 2024-06-03 14:51:15 +02:00
saalen 4e72cf7e15 updated docs 2024-06-03 14:51:15 +02:00
saalen 683a618343 https://sourceforge.net/p/astyle/bugs/574/ avoid deletion of empty lines after continuation 2024-06-03 14:51:01 +02:00
saalen 422985f01b https://sourceforge.net/p/astyle/bugs/572/ fix alignment of logical and operators 2024-06-03 12:52:57 +02:00
saalen 9fd80e1abe updated docs and version 2024-05-16 11:15:42 +02:00
saalen 485382e2aa https://gitlab.com/saalen/astyle/-/issues/35 fix of reference args alignment 2024-05-16 11:13:13 +02:00
saalen b27cccdb9d https://sourceforge.net/p/astyle/bugs/570/ fix padding of scientific notation literals 2024-05-14 23:09:36 +02:00
saalen 8c69e067ec fix padding of lambda capture with align-pointer option 2024-05-07 13:04:16 +02:00
saalen b09b2355e0 https://sourceforge.net/p/astyle/bugs/560/ exclude files ending with backup suffix from input file names list 2024-05-03 15:59:06 +02:00
saalen 86532b948f https://gitlab.com/saalen/astyle/-/issues/35 fix of --align-pointer=type option for all types in lambda parameter lists 2024-05-03 13:14:17 +02:00
saalen 3623229876 https://sourceforge.net/p/astyle/bugs/569/ fix --break-block handling of class and function blocks 2024-05-03 09:37:56 +02:00
saalen bac6279b26 https://sourceforge.net/p/astyle/bugs/566/ fix parsing of floating point literals 2024-05-02 17:09:29 +02:00
Andre Simon 050c108c28 updated astyle readme 2024-04-28 18:01:57 +02:00
saalen bcf5bb4a5e removed getIndentedLineReturn method 2024-04-17 17:16:27 +02:00
saalen 9a77b83a8b enabled C++17 compiler switch 2024-04-09 17:38:46 +02:00
saalen fd449b0e5e replaced const string refs by string_view parameters 2024-04-09 17:27:18 +02:00
saalen 803ba0955a https://gitlab.com/saalen/astyle/-/issues/24 add cmake option to disable documentation installation 2024-04-05 16:05:06 +02:00
saalen 086ed3a3d3 https://gitlab.com/saalen/astyle/-/issues/29 fix of --indent-after-parens indent count 2024-04-04 17:00:44 +02:00
saalen 9af46ccc6c https://gitlab.com/saalen/astyle/-/issues/35 fix of --align-pointer=type option for fundamental types in lambda parameter lists 2024-04-04 16:21:55 +02:00
saalen 04aabdd005 https://sourceforge.net/p/astyle/bugs/565/ fixed split references with -k1 option 2024-03-28 13:27:32 +01:00
saalen 15cf1e018b Merge branch 'master' of gitlab.com:saalen/astyle 2024-03-06 13:01:51 +01:00
saalen f32c555bc1 https://sourceforge.net/p/astyle/bugs/564/ fixed documentation 2024-03-06 12:16:10 +01:00
saalen 7e97becbcf update documentation and notes 2024-03-06 12:07:16 +01:00
saalen 21b58e214e #39 fix comment indent after string macro with R suffix 2024-03-06 12:00:40 +01:00
saalen 16c4a56aa4 #38 do not break single line block after enum in mozilla mode 2024-03-06 10:52:33 +01:00
saalen aa58fe1aa4 #40 adjust cmake policy for new versions only 2024-03-05 15:59:52 +01:00
André Simon 87e0136e5f Merge branch 'master' into 'master'
News page: Fix typo, add last release dates

See merge request saalen/astyle!9
2024-02-24 06:39:44 +00:00
Peu 3bdf5fb041 News page: Fix typo, add last release dates 2024-02-24 06:39:43 +00:00
André Simon b66f3cb173 Merge branch 'master' into 'master'
support scikit-build-core

See merge request saalen/astyle!8
2024-02-12 15:21:55 +00:00
Wu Zhenyu 055c06d4c5 support scikit-build-core
refer https://github.com/scikit-build/scikit-build-core/issues/632#issuecomment-1936946228
we must patch code to avoid more issues down the line
2024-02-10 17:12:38 +08:00
Wu Zhenyu 93605a0147 change /usr/man to /usr/share/man to respect standard 2024-02-10 17:12:12 +08:00
saalen 1c27f34918 https://gitlab.com/saalen/astyle/-/issues/36 fixed addition of closing brace within statement blocks 2024-02-02 17:19:14 +01:00
saalen 96bd14dee1 https://gitlab.com/saalen/astyle/-/issues/36 fixed addition of closing brace after multi line statements 2024-02-01 16:49:20 +01:00
saalen 90499c92cf https://gitlab.com/saalen/astyle/-/issues/36 fixed crash with opening block in next line 2024-01-30 21:21:51 +01:00
saalen cf95606462 updated docs 2024-01-30 16:32:30 +01:00
saalen 05502078e1 https://gitlab.com/saalen/astyle/-/issues/36 fixed crash with --add-braces=nested applied to if-else blocks 2024-01-26 16:22:59 +01:00
saalen 95c9e4f6db https://gitlab.com/saalen/astyle/-/issues/33 added --pad-brackets-in and --pad-brackets-out options 2024-01-19 16:40:02 +01:00
saalen 619081a737 https://gitlab.com/saalen/astyle/-/issues/28 fixed indentation of initializer lists 2024-01-16 10:37:57 +01:00
saalen 3f2b5c92a0 https://gitlab.com/saalen/astyle/-/issues/27 updated notes.html 2024-01-05 17:28:54 +01:00
saalen 99ceeb79b4 https://gitlab.com/saalen/astyle/-/issues/27 avoid assertion error if brace already exists 2024-01-05 17:26:21 +01:00
saalen bbf726c605 https://gitlab.com/saalen/astyle/-/issues/27 add new option --add-braces=nested to add braces around nested one line stmts 2024-01-05 16:59:46 +01:00
saalen 2987c9b361 https://gitlab.com/saalen/astyle/-/issues/28 fix indent of struct members with dot prefix 2024-01-03 16:19:54 +01:00
saalen 48b574fccf updated notes.html 2024-01-02 17:27:41 +01:00
saalen 15ae8d6bdb https://gitlab.com/saalen/astyle/-/issues/28 fix indent after double template brackets 2024-01-02 17:18:19 +01:00
saalen 58710b4b86 https://gitlab.com/saalen/astyle/-/issues/28 fix indent after dot 2024-01-02 15:10:36 +01:00
Andre Simon d31b289c0d https://sourceforge.net/p/astyle/bugs/559/ fix CI pipeline 2024-01-01 21:35:36 +01:00
Andre Simon 9c6e9f942a https://sourceforge.net/p/astyle/bugs/559/ change squeeze line counter int type 2024-01-01 21:24:26 +01:00
André Simon 8218a855f7 https://sourceforge.net/p/astyle/bugs/559/ initialize squeeze line counter 2024-01-01 20:58:57 +01:00
saalen 9a26f1e6d4 https://gitlab.com/saalen/astyle/-/issues/31 add experimental GHC mode 2023-12-29 16:53:22 +01:00
saalen 6f8e619193 https://gitlab.com/saalen/astyle/-/issues/32 fix indent after raw string 2023-12-29 16:01:41 +01:00
saalen a2056ddf70 https://gitlab.com/saalen/astyle/-/issues/26 disable for another approach 2023-11-30 16:52:39 +01:00
saalen c988613837 https://gitlab.com/saalen/astyle/-/issues/26 apply only to C syntax 2023-11-28 15:33:59 +01:00
saalen cea7932ed4 https://gitlab.com/saalen/astyle/-/issues/26 fix indent of switch blocks 2023-11-27 16:38:56 +01:00
saalen 05a5acaf64 https://gitlab.com/saalen/astyle/-/issues/26 fix indent of labels within functions returning a struct 2023-11-27 14:25:06 +01:00
saalen 774bf30237 https://sourceforge.net/p/astyle/bugs/558/ fixed some typos 2023-11-10 16:28:09 +01:00
saalen 824d4b7991 https://gitlab.com/saalen/astyle/-/issues/16 fixed missing indent in function parameter list 2023-10-19 18:17:11 +02:00
21 changed files with 1449 additions and 954 deletions
+5 -1
View File
@@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.8)
cmake_policy(SET CMP0112 OLD)
if(CMAKE_VERSION VERSION_GREATER "3.19.0")
cmake_policy(SET CMP0112 OLD)
endif()
project(astyle CXX)
include( build/cmake/Options.cmake REQUIRED )
+1 -1
View File
@@ -3,7 +3,7 @@ Instructions for using Artistic Style are included in the *doc* directory.
The file **install.html** contains instructions for compiling and
installing Artistic Style.
The file **astyle.html**' contains information on using Artistic Style.
The file **astyle.html** contains information on using Artistic Style.
The files **news.html** and **notes.html** contain information on changes
made to the various releases.
+3 -3
View File
@@ -1,8 +1,8 @@
# Set default compile options for supported compilers
if(APPLE)
target_compile_options( astyle PRIVATE -W -Wall -fno-rtti -fno-exceptions -std=c++11 -stdlib=libc++)
target_compile_options( astyle PRIVATE -W -Wall -fno-rtti -fno-exceptions -std=c++17 -stdlib=libc++)
elseif(NOT WIN32) # Linux
target_compile_options(astyle PRIVATE -Wall -Wextra -fno-rtti -fno-exceptions -std=c++11)
target_compile_options(astyle PRIVATE -Wall -Wextra -fno-rtti -fno-exceptions -std=c++17)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "gnu")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (NOT (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6))
@@ -13,7 +13,7 @@ elseif(NOT WIN32) # Linux
target_compile_options(astyle PRIVATE -wd11074,11076)
endif()
elseif(MINGW)
target_compile_options(astyle PRIVATE -Wall -Wextra -fno-rtti -fno-exceptions -std=c++11)
target_compile_options(astyle PRIVATE -Wall -Wextra -fno-rtti -fno-exceptions -std=c++17)
elseif(BORLAND) # Release must be explicitly requested for Borland
target_compile_options(astyle PRIVATE -q -w -x-) # Cannot use no-rtti (-RT-)
endif()
+17 -4
View File
@@ -3,12 +3,21 @@
# Default linux install prefix is /usr/local"
# This may be modified by -DCMAKE_INSTALL_PREFIX=
# Default Win32 install prefix is not used (C:/Program Files (x86))
option(INSTALL_DOC ON)
if(BUILD_SHARED_LIBS OR BUILD_STATIC_LIBS)
if(NOT WIN32)
install(TARGETS astyle DESTINATION lib)
endif()
else()
if(WIN32)
if(SKBUILD)
install(TARGETS astyle DESTINATION "${SKBUILD_SCRIPTS_DIR}")
if(INSTALL_DOC)
install(FILES ${DOCS} DESTINATION "${SKBUILD_DATA_DIR}/share/doc/astyle/html")
install(FILES ${MAN} DESTINATION "${SKBUILD_DATA_DIR}/share/man/man1")
endif()
elseif(WIN32)
set(pf86 "PROGRAMFILES(x86)")
set(prog_files $ENV{${pf86}})
if(NOT ${prog_files})
@@ -19,14 +28,18 @@ else()
elseif(APPLE)
# install to the default /usr/local/bin because of SIP restrictions
install(TARGETS astyle DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
install(FILES ${DOCS} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/doc/astyle/html")
if(INSTALL_DOC)
install(FILES ${DOCS} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/doc/astyle/html")
endif()
else()
# change default to /usr/bin, the same as package installs
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr")
endif()
install(TARGETS astyle DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
install(FILES ${DOCS} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/doc/astyle/html")
INSTALL(FILES ${MAN} DESTINATION "${CMAKE_INSTALL_PREFIX}/man/man1")
if(INSTALL_DOC)
install(FILES ${DOCS} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/doc/astyle/html")
install(FILES ${MAN} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/man/man1")
endif()
endif()
endif()
+1 -1
View File
@@ -10,7 +10,7 @@ endif()
# Linux Soname Version
set(MAJORVER 3)
set(MINORVER 4)
set(MINORVER 5)
set(PATCHVER 0)
set(SOLIBVER ${MAJORVER}.${MINORVER}.${PATCHVER})
+87 -19
View File
@@ -60,7 +60,7 @@
<button onclick="topFunction()" id="topBtn" title="Go to Contents"><b>Top</b></button>
<h1>Artistic Style 3.4.9</h1>
<h1>Artistic Style</h1>
<h2>
A Free, Fast, and Small Automatic Formatter<br />
@@ -111,7 +111,7 @@
<a class="contents" href="#_indent=spaces">indent=spaces</a>
<a class="contents" href="#_indent=tab">indent=tab</a>
<a class="contents" href="#_indent=force-tab">indent=force-tab</a>
<a class="contents" href="#_indent=force-tab-x">--indent=force-tab-x</a>
<a class="contents" href="#_indent=force-tab-x">indent=force-tab-x</a>
</p>
<p class="contents1">
<a href="#_Brace_Modify_Options">Brace&nbsp;Modify&nbsp;Options</a></p>
@@ -139,7 +139,7 @@
<a class="contents" href="#_indent-col1-comments">indent-col1-comments</a>
<a class="contents" href="#_min-conditional-indent">min-conditional-indent</a>
<a class="contents" href="#_max-continuation-indent">max-continuation-indent</a>
<a class="contents" href="#_lambda_indent">lambda-indent</a>
<a class="contents" href="#_indent_lambda">indent-lambda</a>
</p>
<p class="contents1">
@@ -149,6 +149,7 @@
<a class="contents" href="#_break-blocks=all">break-blocks=all</a>
<a class="contents" href="#_pad-oper">pad-oper</a>
<a class="contents" href="#_pad-comma">pad-comma</a>
<a class="contents" href="#_pad-negation">pad-negation</a>
<a class="contents" href="#_pad-paren">pad-paren</a>
<a class="contents" href="#_pad-paren-out">pad-paren-out</a>
<a class="contents" href="#_pad-first-paren-out">pad-first-paren-out</a>
@@ -157,6 +158,8 @@
<a class="contents" href="#_unpad-paren">unpad-paren</a>
<a class="contents" href="#_pad-empty-paren">pad-empty-paren</a>
<a class="contents" href="#_pad-brackets">pad-brackets</a>
<a class="contents" href="#_pad-brackets-in">pad-brackets-in</a>
<a class="contents" href="#_pad-brackets-out">pad-brackets-out</a>
<a class="contents" href="#_unpad-brackets">unpad-brackets</a>
<a class="contents" href="#_delete-empty-lines">delete-empty-lines</a>
<a class="contents" href="#_fill-empty-lines">fill-empty-lines</a>
@@ -400,7 +403,7 @@
<h4>Redirection</h4>
<p>
The < and > characters may be used to redirect the files into standard input (stdin) and out of standard output
The &lt; and &gt; characters may be used to redirect the files into standard input (stdin) and out of standard output
(stdout) - don't forget them! With this option, only one file at a time can be formatted. Wildcards are not
recognized, there are no console messages, and a backup is not created. On Windows, the output will always have
Windows line ends. The options "stdin=" and "stdout=" can be used instead of redirection.</p>
@@ -414,7 +417,8 @@
<pre>astyle --style=allman --stdin=<em>OriginalSourceFile</em> --stdout=<em>BeautifiedSourceFile</em>
</pre>
</div>
<div class="code">
<div class="code" style="margin-top:1em">
<p class="code">
The redirection option may be used to display the formatted file without updating:</p>
<pre>astyle --style=allman &lt; <em>OriginalSourceFile</em> | less
@@ -1545,8 +1549,8 @@ fooFunction(barArg1,
</pre>
</div>
<p id="_lambda_indent">
<code class="title">--lambda-indent</code><br />
<p id="_indent_lambda">
<code class="title">--indent-lambda</code><br />
This option improves indentation of C++ lambda functions. As it currently does not work well with complex lambda function bodies, this feature is not enabled by default.
</p>
@@ -1671,6 +1675,41 @@ isBar = false;
bar(a, b);
</pre>
</div>
<p>
&nbsp;</p>
<p id="_pad-negation">
<code class="title">--pad-negation</code><br />
Insert space padding after negations.
</p>
<div class="code">
<pre>if (!isFoo(a,b))
bar(a,b);
</pre>
<p class="code">
becomes:</p>
<pre>if (! isFoo(a, b))
bar(a, b);
</pre>
</div>
<p>
&nbsp;</p>
<p id="_pad-negation">
<code class="title">--pad-negation=before</code><br />
Insert space padding also before negations.
</p>
<div class="code">
<pre>if (!isFoo(a,b))
bar(a,b);
</pre>
<p class="code">
becomes:</p>
<pre>if ( ! isFoo(a, b))
bar(a, b);
</pre>
</div>
<p>
&nbsp;</p>
<p id="_pad-paren">
@@ -1818,6 +1857,31 @@ isBar = false;
<pre>a = b [ a [ 1 ] ];</pre>
</div>
<p id="_pad-brackets-in">
<code class="title">--pad-brackets-in</code>
<br />
Insert space padding around square brackets the <strong>inside</strong> only.
</p>
<div class="code">
<pre>a = b[a[1]];</pre>
<p class="code">
becomes:</p>
<pre>a = b[ a[ 1 ] ];</pre>
</div>
<p id="_pad-brackets-out">
<code class="title">--pad-brackets-out</code>
<br />
Insert space padding around square brackets the <strong>outside</strong> only.
</p>
<div class="code">
<pre>a = b[a[1]];</pre>
<p class="code">
becomes:</p>
<pre>a = b [a [1]];</pre>
</div>
<p id="_unpad-brackets">
<code class="title">--unpad-brackets</code>
<br />
@@ -1936,7 +2000,7 @@ string ^s1;</pre>
char&amp; foo2;
string^ s1;</pre>
</div>
<div class="code">
<div class="code" style="margin-top:1em">
<pre>char* foo1;
char &amp; foo2;
string ^s1;</pre>
@@ -1946,7 +2010,7 @@ string ^s1;</pre>
char &amp; foo2;
string ^ s1;</pre>
</div>
<div class="code">
<div class="code" style="margin-top:1em">
<pre>char* foo1;
char &amp; foo2;
string ^s1;</pre>
@@ -1974,14 +2038,14 @@ string ^s1;</pre>
becomes (with align-reference=type):</p>
<pre>char&amp; foo1;</pre>
</div>
<div class="code">
<div class="code" style="margin-top:1em">
<pre>char&amp; foo2;</pre>
<p class="code">
becomes (with align-reference=middle):</p>
<pre>char &amp; foo2;</pre>
</div>
<div class="code">
<pre>char& foo3;</pre>
<div class="code" style="margin-top:1em">
<pre>char&amp; foo3;</pre>
<p class="code">
becomes (with align-reference=name):</p>
<pre>char &amp;foo3;</pre>
@@ -2146,7 +2210,7 @@ else
<p>
&nbsp;</p>
<p id="_break-return-type">
<code class="title">--break-return-type &nbsp;&nbsp; / -xB</code><br />
<code class="title">--break-return-type &nbsp;&nbsp;&nbsp;&nbsp; / -xB</code><br />
<code class="title">--break-return-type-decl / -xD</code><br />
Break the return type from the function name. The two options are for the function definitions (-xB), and the
function declarations or signatures (-xD). If used with --attach-return-type, the result will be to break the
@@ -2161,7 +2225,7 @@ Foo(bool isFoo);</pre>
<p>
&nbsp;</p>
<p id="_attach-return-type">
<code class="title">--attach-return-type &nbsp;&nbsp; / -xf</code><br />
<code class="title">--attach-return-type &nbsp;&nbsp;&nbsp;&nbsp; / -xf</code><br />
<code class="title">--attach-return-type-decl / -xh</code><br />
Attach the return type to the function name. The two options are for the function definitions (-xf), and the
function declarations or signatures (-xh). They are intended to undo the --break-return-type options. If used
@@ -2288,10 +2352,14 @@ Foo(bool isFoo);</pre>
<code class="title">--mode=js</code><br />
<code class="title">--mode=java</code><br />
<code class="title">--mode=objc</code><br />
Indent a C type, C#, Javascript, Java or <span style="white-space: nowrap;">Objective-C</span> file. C type files are C, C++, C++/CLI. The option is usually
set from the file extension for each file. You can override the setting with this entry. It will be used for all
files, regardless of the file extension. It allows the formatter to identify language specific syntax such as
C++ classes, templates, and keywords.</p>
<code class="title">--mode=js <i>(experimental)</i></code><br />
<code class="title">--mode=ghc <i>(experimental)</i></code><br />
Indent a C type, C#, Javascript, Java or <span style="white-space: nowrap;">Objective-C</span> file.
JS and GHC support is experimental.
C type files are C, C++, C++/CLI. The option is usually set from the file extension for each file.
You can override the setting with this entry. It will be used for all files, regardless of the file extension.
It allows the formatter to identify language specific syntax such as C++ classes, templates, and keywords.
</p>
<p>
&nbsp;</p>
<hr />
@@ -2440,7 +2508,7 @@ Foo(bool isFoo);</pre>
&nbsp;</p>
<p id="_pad-method-colon">
<code class="title">--pad-method-colon=none&nbsp;&nbsp; / -xP0<br />
--pad-method-colon=all / -xP1<br />
--pad-method-colon=all&nbsp;&nbsp;&nbsp; / -xP1<br />
--pad-method-colon=after&nbsp; / -xP2<br />
--pad-method-colon=before / -xP3
</code><br />
+1 -1
View File
@@ -14,7 +14,7 @@
<!-- body text -->
<h1>Artistic Style 3.4.9</h1>
<h1>Artistic Style</h1>
<h2>
A Free, Fast, and Small Automatic Formatter<br />
+610 -609
View File
File diff suppressed because it is too large Load Diff
+97 -33
View File
@@ -14,71 +14,135 @@
<h1>Artistic Style Release Notes</h1>
<h3>Artistic Style 3.4.9 (September 2023)</h3>
<h3>Artistic Style 3.5 (June 2024)</h3>
<ul>
<li>Add option --pad-negation (https://sourceforge.net/p/astyle/bugs/571)</li>
<li>Apply align-pointer=type only if type is present (https://sourceforge.net/p/astyle/bugs/573)</li>
<li>Avoid deletion of empty lines after continuation (https://sourceforge.net/p/astyle/bugs/574)</li>
<li>Fix alignment of logical AND operators (https://sourceforge.net/p/astyle/bugs/572)</li>
<li>Fix recognition of Java/C# multi line strings (https://gitlab.com/saalen/astyle/-/issues/42)</li>
</ul>
<h3>Artistic Style 3.4.16 (May 2024)</h3>
<ul>
<li>Fix padding of scientific notation literals (#570)</li>
<li>Fix of reference args alignment (https://gitlab.com/saalen/astyle/-/issues/35)</li>
</ul>
<h3>Artistic Style 3.4.15 (May 2024)</h3>
<ul>
<li>Fix parsing of floating point literals (#566)</li>
<li>Fix "--break-block" handling of class and function blocks (#569)</li>
<li>Fix "--align-pointer=type" option for all types in lambda parameter lists (https://gitlab.com/saalen/astyle/-/issues/35)</li>
<li>Fix padding of lambda capture with align-pointer option</li>
<li>Exclude files ending with backup suffix from input file names list (#560)</li>
</ul>
<h3>Artistic Style 3.4.14 (April 2024)</h3>
<ul>
<li>Fix split references with "-k1" option (#565)</li>
<li>Fix "--align-pointer=type" option for fundamental types in lambda parameter lists (https://gitlab.com/saalen/astyle/-/issues/35)</li>
<li>Fix "--indent-after-parens" indent count (https://gitlab.com/saalen/astyle/-/issues/29)</li>
</ul>
<h3>Artistic Style 3.4.13 (March 2024)</h3>
<ul>
<li>Fix comment indent after string macro with R suffix (https://gitlab.com/saalen/astyle/-/issues/39)</li>
<li>Do not break single line block after enum in mozilla mode (https://gitlab.com/saalen/astyle/-/issues/38)</li>
<li>Adjust cmake policy for new versions only (https://gitlab.com/saalen/astyle/-/issues/40)</li>
<li>Update man page path</li>
<li>Add support for scikit-build-core</li>
</ul>
<h3>Artistic Style 3.4.12 (February 2024)</h3>
<ul>
<li>Add "--pad-brackets-in" and "--pad-brackets-out" options (https://gitlab.com/saalen/astyle/-/issues/33)</li>
<li>Fix indentation of initializer lists (https://gitlab.com/saalen/astyle/-/issues/28)</li>
<li>Fix crash with "--add-braces=nested" applied to if-else blocks (https://gitlab.com/saalen/astyle/-/issues/36)</li>
</ul>
<h3>Artistic Style 3.4.11 (January 2024)</h3>
<ul>
<li>applied one wording for <span style="white-space: nowrap;">Objective-C</span> in the docs</li>
<li>fixed more CS regressions (https://gitlab.com/saalen/astyle/-/issues/16)</li>
<li>fixed inserting space with combined "--pad-oper" and "--align-pointer" options (#557)</li>
<li>Add new option "--add-braces=nested" to add braces in nested single line statements (https://gitlab.com/saalen/astyle/-/issues/27)</li>
<li>Fix indent after double template brackets (https://gitlab.com/saalen/astyle/-/issues/28)</li>
<li>Fix indent after dot (https://gitlab.com/saalen/astyle/-/issues/28)</li>
<li>Option "--squeeze-lines=1" is no longer default with Linux builds (#559)</li>
<li>Add experimental GHC mode (https://gitlab.com/saalen/astyle/-/issues/31)</li>
<li>Fix indent after raw string (https://gitlab.com/saalen/astyle/-/issues/32)</li>
</ul>
<h3>Artistic Style 3.4.10 (October 2023)</h3>
<ul>
<li>Fix missing indent in function parameter list (https://gitlab.com/saalen/astyle/-/issues/16)</li>
</ul>
<h3>Artistic Style 3.4.9 (October 2023)</h3>
<ul>
<li>Apply one wording for <span style="white-space: nowrap;">Objective-C</span> in the docs</li>
<li>Fix more CS regressions (https://gitlab.com/saalen/astyle/-/issues/16)</li>
<li>Fix inserting space with combined "--pad-oper" and "--align-pointer" options (#557)</li>
</ul>
<h3>Artistic Style 3.4.8 (September 2023)</h3>
<ul>
<li>fixed lambda broken brace after auto keyword (#554)</li>
<li>fixed line break after comment in asm block (#226)</li>
<li>fixed padding of multiply operator (#126)</li>
<li>fixed indentation of method calls (#434)</li>
<li>fixed empty line after closing while block (https://gitlab.com/saalen/astyle/-/issues/18)</li>
<li>added outer padding for emtpy parens pairs (https://gitlab.com/saalen/astyle/-/issues/19) </li>
<li>fixed more CS regressions (https://gitlab.com/saalen/astyle/-/issues/16)</li>
<li>Fix lambda broken brace after auto keyword (#554)</li>
<li>Fix line break after comment in asm block (#226)</li>
<li>Fix padding of multiply operator (#126)</li>
<li>Fix indentation of method calls (#434)</li>
<li>Fix empty line after closing while block (https://gitlab.com/saalen/astyle/-/issues/18)</li>
<li>Add outer padding for empty parens pairs (https://gitlab.com/saalen/astyle/-/issues/19) </li>
<li>Fix more CS regressions (https://gitlab.com/saalen/astyle/-/issues/16)</li>
</ul>
<h3>Artistic Style 3.4.6 (August 2023)</h3>
<ul>
<li>added VS2022 project files (https://gitlab.com/saalen/astyle/-/merge_requests/3)</li>
<li>fixed CS regressions (https://gitlab.com/saalen/astyle/-/issues/16)</li>
<li>added CS coalesce assignment operator (https://gitlab.com/saalen/astyle/-/issues/17)</li>
<li>Add VS2022 project files (https://gitlab.com/saalen/astyle/-/merge_requests/3)</li>
<li>Fix CS regressions (https://gitlab.com/saalen/astyle/-/issues/16)</li>
<li>Add CS coalesce assignment operator (https://gitlab.com/saalen/astyle/-/issues/17)</li>
</ul>
<h3>Artistic Style 3.4.1 (August 2023)</h3>
<ul>
<li>fixed padding of &amp; following a comma (#552)</li>
<li>fixed indent of function declarations following access modifiers (#504)</li>
<li>fixed indent of C# allocation blocks (#464)</li>
<li>fixed indentation of comments after CS interpolation quotes (https://gitlab.com/saalen/astyle/-/issues/16)</li>
<li>Fix padding of &amp; following a comma (#552)</li>
<li>Fix indent of function declarations following access modifiers (#504)</li>
<li>Fix indent of C# allocation blocks (#464)</li>
<li>Fix indentation of comments after CS interpolation quotes (https://gitlab.com/saalen/astyle/-/issues/16)</li>
</ul>
<h3>Artistic Style 3.4 (June 2023)</h3>
<ul>
<li>fixed formatting of CS interpolation literals (https://gitlab.com/saalen/astyle/-/issues/8).</li>
<li>fixed false lambda recognition (https://gitlab.com/saalen/astyle/-/issues/11)</li>
<li>fixed indentation of member declarations (https://gitlab.com/saalen/astyle/-/issues/10)</li>
<li>fixed indentation of struct assignments (https://gitlab.com/saalen/astyle/-/issues/12)</li>
<li>added new option "--indent-lambda" to to enable new lambda recognition (https://gitlab.com/saalen/astyle/-/issues/7)</li>
<li>added link to astyle Python distribution projects (https://gitlab.com/saalen/astyle/-/issues/6)</li>
<li>Fix formatting of CS interpolation literals (https://gitlab.com/saalen/astyle/-/issues/8).</li>
<li>Fix false lambda recognition (https://gitlab.com/saalen/astyle/-/issues/11)</li>
<li>Fix indentation of member declarations (https://gitlab.com/saalen/astyle/-/issues/10)</li>
<li>Fix indentation of struct assignments (https://gitlab.com/saalen/astyle/-/issues/12)</li>
<li>Add new option "--indent-lambda" to enable new lambda recognition (https://gitlab.com/saalen/astyle/-/issues/7)</li>
<li>Add link to astyle Python distribution projects (https://gitlab.com/saalen/astyle/-/issues/6)</li>
</ul>
<h3>Artistic Style 3.3 (May 2023)</h3>
<ul>
<li>added new option "--squeeze-ws" to remove superfluous whitespace (experimental)</li>
<li>added new option "--squeeze-lines" to remove superfluous empty lines (experimental, #19, #22, #43, #72, #84, #93, #105, #517)</li>
<li>added new options "--pad-brackets" and "--unpad-brackets" to add or remove whitespace around square brackets (experimental)</li>
<li>fixed indent of lambda bodies in fct calls (#121)</li>
<li>fixed indent of struct names including &quot;struct&quot; (#526)</li>
<li>fixed indent of C++11 initializer lists (#516)</li>
<li>fixed padding of pointers separated by comma (#537)</li>
<li>refactored namespace std usage</li>
<li>Add new option "--squeeze-ws" to remove superfluous whitespace (experimental)</li>
<li>Add new option "--squeeze-lines" to remove superfluous empty lines (experimental, #19, #22, #43, #72, #84, #93, #105, #517)</li>
<li>Add new options "--pad-brackets" and "--unpad-brackets" to add or remove whitespace around square brackets (experimental)</li>
<li>Fix indent of lambda bodies in fct calls (#121)</li>
<li>Fix indent of struct names including &quot;struct&quot; (#526)</li>
<li>Fix indent of C++11 initializer lists (#516)</li>
<li>Fix padding of pointers separated by comma (#537)</li>
<li>Refactor namespace std usage</li>
</ul>
<h3>Artistic Style 3.2.1 (March 2023)</h3>
<ul>
<li>fixed struct recognition related to SF #534 (https://gitlab.com/saalen/astyle/-/issues/1)</li>
<li>Fix struct recognition related to SF #534 (https://gitlab.com/saalen/astyle/-/issues/1)</li>
</ul>
<h3>Artistic Style 3.2 (March 2023)</h3>
+4 -5
View File
@@ -876,7 +876,7 @@
<li>Compilation under G++ 3.0 now works properly.</li>
<li>Bug fix: Opening brackets that appear at the beginning of a line immediately after an empty line comment are now
handled properly, and not appended as part of the line comment.</li>
<li>Bug fix: Brackets inside comments are now not mis-indented within the comment.</li>
<li>Bug fix: Brackets inside comments are properly indented within the comment.</li>
</ul>
<h3>Artistic Style 1.14.1 (2 June 2001)</h3>
@@ -1015,13 +1015,13 @@
<h3>Artistic Style 1.11.1 (3 September 1999)</h3>
<ul>
<li>Fixed a bug that inserted an empty line at the begining of source files.</li>
<li>Fixed a bug that inserted an empty line at the beginning of source files.</li>
</ul>
<h3>Artistic Style 1.11.0 (3 September 1999)</h3>
<ul>
<li>Astyle now filters out line-feeds ('\r') before begining to parse lines. This should take care of bizarre formatting
<li>Astyle now filters out line-feeds ('\r') before beginning to parse lines. This should take care of bizarre formatting
that existed when moving source files from Windows (which breaks lines with a linefeed AND newline ("\r\n") to
unix (which breaks lines only with newlines).</li>
<li>The "struct", "static" and "synchronized" keywords are now finally handled correctly in both the contexts of block
@@ -1088,7 +1088,7 @@
for similarity with the new option above.</li>
<li>Changed the short option name of the option '-<strong>-errors-to-standard-output</strong>' from '<strong>-o</strong>'
to '<strong>-X</strong>'.</li>
<li>Up to now, Artistic Style always inserted a minimal indent of <strong>t</strong>wice the current selected indent
<li>Up to now, Artistic Style always inserted a minimal indent of <strong>twice</strong> the current selected indent
size inside multi-line conditional headers ('if', 'while' ...), so that it would be clear where the headers end
and the code after them begins. The current version adds the option '<strong>--min-conditional-indent=#</strong>'
(or '<strong>-m#</strong>') that sets the absolute minimal indent between conditional headers and their multiple-line
@@ -1347,4 +1347,3 @@
</body>
</html>
+21 -5
View File
@@ -1,4 +1,4 @@
.TH astyle 1 "2023-09-21" "Andre Simon" "user documentation"
.TH astyle 1 "2024-05-03" "Andre Simon" "user documentation"
.SH NAME
astyle - C syntax indenter and formatter
@@ -218,6 +218,12 @@ Insert space padding around operators.
.IP "--pad-comma OR -xg"
Insert space padding after commas.
.IP "--pad-negation"
Insert space padding after negations.
.IP "--pad-negation=before"
Insert space padding also before negations.
.IP "--pad-paren OR -P"
Insert space padding around parenthesis on both the outside
and the inside.
@@ -245,10 +251,16 @@ parenthesis padding options.
.IP "--pad-brackets"
Insert space padding around square brackets on both the outside
and the inside (experimental).
and the inside.
.IP "--pad-brackets-in"
Insert space padding around square brackets the inside only.
.IP "--pad-brackets-out"
Insert space padding around square brackets the outside only.
.IP "--unpad-brackets"
Remove unnecessary space padding around square brackets (experimental).
Remove unnecessary space padding around square brackets.
.IP "--delete-empty-lines OR -xe"
Delete empty lines within a function or method.
@@ -274,10 +286,10 @@ the operator type (left), middle, or operator name (right).
If not set, follow pointer alignment.
.IP "--squeeze-lines=#"
Remove superfluous empty lines exceeding the given number (experimental).
Remove superfluous empty lines exceeding the given number.
.IP "--squeeze-ws"
Remove superfluous whitespace (experimental).
Remove superfluous whitespace.
.SH Formatting Options
@@ -293,6 +305,7 @@ Break one line headers (e.g. 'if', 'while', 'else', ...) from a
statement residing on the same line.
.IP "--add-braces OR -j"
.IP "--add-braces=nested (experimental)"
Add braces to unbraced one line conditional statements.
.IP "--add-one-line-braces OR -J"
@@ -353,6 +366,9 @@ Indent an Objective-C source file.
.IP "--mode=js"
Indent a JavaScript source file (experimental).
.IP "--mode=ghc"
Indent a GHC source file (experimental).
.SH Objective-C Options
.IP "--pad-method-prefix OR -xQ"
+1 -1
View File
@@ -4,7 +4,7 @@ _astyle() {
args=("${COMP_WORDS[@]}")
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--style --indent --attach-namespaces --attach-classes --attach-inlines --attach-extern-c --attach-closing-while --indent-classes --indent-modifiers --indent-switches --indent-cases --indent-namespaces --indent-after-parens --indent-continuation --indent-labels --indent-preproc-block --indent-preproc-cond --indent-preproc-define --indent-col1-comments --min-conditional-indent --max-continuation-indent --break-blocks --pad-oper --pad-comma --pad-paren --pad-paren-out --pad-first-paren-out --pad-paren-in --pad-header --unpad-paren --pad-empty-paren --pad-brackets --unpad-brackets --delete-empty-lines --fill-empty-lines --align-pointer --align-reference --break-closing-braces --break-elseifs --break-one-line-headers --add-braces --add-one-line-braces --remove-braces --break-return-type --attach-return-type-decl --keep-one-line-blocks --keep-one-line-statements --convert-tabs --close-templates --remove-comment-prefix --max-code-length --break-after-logical mode --pad-method-prefix --unpad-method-prefix --pad-return-type --unpad-return-type --pad-param-type --unpad-param-type --align-method-colon --pad-method-colon --suffix --recursive --dry-run --exclude --ignore-exclude-errors --ignore-exclude-errors-x --errors-to-stdout --preserve-date --verbose --formatted --quiet --lineend --options --project --ascii --version --help --html --stdin --stdout --squeeze-lines --squeeze-ws"
opts="--style --indent --attach-namespaces --attach-classes --attach-inlines --attach-extern-c --attach-closing-while --indent-classes --indent-modifiers --indent-switches --indent-cases --indent-namespaces --indent-after-parens --indent-continuation --indent-labels --indent-preproc-block --indent-preproc-cond --indent-preproc-define --indent-col1-comments --min-conditional-indent --max-continuation-indent --break-blocks --pad-oper --pad-comma --pad-negation --pad-paren --pad-paren-out --pad-first-paren-out --pad-paren-in --pad-header --unpad-paren --pad-empty-paren --pad-brackets --unpad-brackets --delete-empty-lines --fill-empty-lines --align-pointer --align-reference --break-closing-braces --break-elseifs --break-one-line-headers --add-braces --add-one-line-braces --remove-braces --break-return-type --attach-return-type-decl --keep-one-line-blocks --keep-one-line-statements --convert-tabs --close-templates --remove-comment-prefix --max-code-length --break-after-logical mode --pad-method-prefix --unpad-method-prefix --pad-return-type --unpad-return-type --pad-param-type --unpad-param-type --align-method-colon --pad-method-colon --suffix --recursive --dry-run --exclude --ignore-exclude-errors --ignore-exclude-errors-x --errors-to-stdout --preserve-date --verbose --formatted --quiet --lineend --options --project --ascii --version --help --html --stdin --stdout --squeeze-lines --squeeze-ws"
case "$prev" in
--style)
+10 -1
View File
@@ -89,6 +89,9 @@ parser:flag "--pad-oper"
parser:flag "--pad-comma"
:description "Insert space padding after commas"
parser:flag "--pad-negation"
:description "Insert space padding after negations"
parser:flag "--pad-paren"
:description "Insert space padding around parenthesis on both the outside and the inside"
@@ -108,7 +111,13 @@ parser:flag "--unpad-paren"
:description "Remove unnecessary space padding around parenthesis"
parser:flag "--pad-brackets"
:description "Insert space padding around square brackets on both the outside and the inside (experimental)."
:description "Insert space padding around square brackets on both the outside and the inside."
parser:flag "--pad-brackets-in"
:description "Insert space padding around square brackets on the inside only."
parser:flag "--pad-brackets-out"
:description "Insert space padding around square brackets on the outside only."
parser:flag "--unpad-brackets"
:description "Remove unnecessary space padding around square brackets (experimental)."
+162 -69
View File
@@ -72,6 +72,7 @@ ASBeautifier::ASBeautifier()
setPreprocDefineIndent(false);
setPreprocConditionalIndent(false);
setAlignMethodColon(false);
isInAssignment = isInInitializerList = isInMultiLineString = false;
// initialize ASBeautifier member vectors
beautifierFileType = INVALID_TYPE; // reset to an invalid type
@@ -209,6 +210,10 @@ ASBeautifier::ASBeautifier(const ASBeautifier& other) : ASBase(other)
caseIndent = other.caseIndent;
squeezeWhitespace = other.squeezeWhitespace;
attemptLambdaIndentation = other.attemptLambdaIndentation;
isInAssignment = other.isInAssignment;
isInInitializerList = other.isInInitializerList;
isInMultiLineString = other.isInMultiLineString;
namespaceIndent = other.namespaceIndent;
braceIndent = other.braceIndent;
braceIndentVtk = other.braceIndentVtk;
@@ -602,16 +607,16 @@ std::string ASBeautifier::beautify(const std::string& originalLine)
&& line.length() > 0
&& line[0] != '#')
{
std::string indentedLine;
if (isIndentModeOff)
return originalLine;
if (isInClassHeaderTab || isInClassInitializer)
{
// parsing is turned off in ASFormatter by indent-off
// the originalLine will probably never be returned here
indentedLine = preLineWS(prevFinalLineIndentCount, prevFinalLineSpaceIndentCount) + line;
return getIndentedLineReturn(indentedLine, originalLine);
return preLineWS(prevFinalLineIndentCount, prevFinalLineSpaceIndentCount) + line;
}
indentedLine = preLineWS(preprocBlockIndent, 0) + line;
return getIndentedLineReturn(indentedLine, originalLine);
return preLineWS(preprocBlockIndent, 0) + line;
}
if (!isInComment
@@ -646,10 +651,18 @@ std::string ASBeautifier::beautify(const std::string& originalLine)
}
else
indentedLine = preLineWS(preprocBlockIndent, 0) + line;
return getIndentedLineReturn(indentedLine, originalLine);
if (isIndentModeOff)
return originalLine;
else
return indentedLine;
}
if (shouldIndentPreprocConditional && preproc.length() > 0)
{
if (isIndentModeOff)
return originalLine;
std::string indentedLine;
if (preproc.length() >= 2 && preproc.substr(0, 2) == "if") // #if, #ifdef, #ifndef
{
@@ -661,7 +674,7 @@ std::string ASBeautifier::beautify(const std::string& originalLine)
preprocIndentStack->emplace_back(entry);
indentedLine = preLineWS(preprocIndentStack->back().first,
preprocIndentStack->back().second) + line;
return getIndentedLineReturn(indentedLine, originalLine);
return indentedLine;
}
if (preproc == "else" || preproc == "elif")
{
@@ -669,7 +682,7 @@ std::string ASBeautifier::beautify(const std::string& originalLine)
{
indentedLine = preLineWS(preprocIndentStack->back().first,
preprocIndentStack->back().second) + line;
return getIndentedLineReturn(indentedLine, originalLine);
return indentedLine;
}
}
else if (preproc == "endif")
@@ -679,7 +692,7 @@ std::string ASBeautifier::beautify(const std::string& originalLine)
indentedLine = preLineWS(preprocIndentStack->back().first,
preprocIndentStack->back().second) + line;
preprocIndentStack->pop_back();
return getIndentedLineReturn(indentedLine, originalLine);
return indentedLine;
}
}
}
@@ -699,14 +712,14 @@ std::string ASBeautifier::beautify(const std::string& originalLine)
{
isInDefineDefinition = false;
// this could happen with invalid input
if (activeBeautifierStack->empty())
if (activeBeautifierStack->empty() || isIndentModeOff)
return originalLine;
ASBeautifier* defineBeautifier = activeBeautifierStack->back();
activeBeautifierStack->pop_back();
std::string indentedLine = defineBeautifier->beautify(line);
delete defineBeautifier;
return getIndentedLineReturn(indentedLine, originalLine);
return indentedLine;
}
// unless this is a multi-line #define, return this precompiler line as is.
@@ -749,7 +762,7 @@ std::string ASBeautifier::beautify(const std::string& originalLine)
size_t iPrelim = headerStack->size();
// calculate preliminary indentation based on headerStack and data from past lines
computePreliminaryIndentation();
computePreliminaryIndentation(line);
// parse characters in the current line.
parseCurrentLine(line);
@@ -800,8 +813,7 @@ std::string ASBeautifier::beautify(const std::string& originalLine)
indentCount = spaceIndentCount = 0;
// finally, insert indentations into beginning of line
std::string indentedLine = preLineWS(indentCount, spaceIndentCount) + line;
indentedLine = getIndentedLineReturn(indentedLine, originalLine);
std::string indentedLine = isIndentModeOff ? originalLine : preLineWS(indentCount, spaceIndentCount) + line;
prevFinalLineSpaceIndentCount = spaceIndentCount;
prevFinalLineIndentCount = indentCount;
@@ -856,6 +868,14 @@ void ASBeautifier::setSharpStyle()
fileType = SHARP_TYPE;
}
/**
* set indentation style to GHC.
*/
void ASBeautifier::setGHCStyle()
{
fileType = GHC_TYPE;
}
/**
* set mode manually set flag
*/
@@ -1301,13 +1321,6 @@ int ASBeautifier::getTabLength() const
return tabLength;
}
const std::string& ASBeautifier::getIndentedLineReturn(const std::string& newLine, const std::string& originalLine) const
{
if (isIndentModeOff)
return originalLine;
return newLine;
}
std::string ASBeautifier::preLineWS(int lineIndentCount, int lineSpaceIndentCount) const
{
if (shouldForceTabIndentation)
@@ -1338,9 +1351,10 @@ std::string ASBeautifier::preLineWS(int lineIndentCount, int lineSpaceIndentCoun
/**
* register a continuation indent.
*/
void ASBeautifier::registerContinuationIndent(const std::string& line, int i, int spaceIndentCount_,
void ASBeautifier::registerContinuationIndent(std::string_view line, int i, int spaceIndentCount_,
int tabIncrementIn, int minIndent, bool updateParenStack)
{
//return;
assert(i >= -1);
int remainingCharNum = line.length() - i;
int nextNonWSChar = getNextProgramCharDistance(line, i);
@@ -1350,14 +1364,25 @@ void ASBeautifier::registerContinuationIndent(const std::string& line, int i, in
if (nextNonWSChar == remainingCharNum || shouldIndentAfterParen)
{
int previousIndent = spaceIndentCount_;
if (!continuationIndentStack->empty())
previousIndent = continuationIndentStack->back();
int currIndent = continuationIndent * indentLength + previousIndent;
// GL29
if (shouldIndentAfterParen) {
currIndent = indentLength;
}
if (currIndent > maxContinuationIndent && line[i] != '{')
currIndent = indentLength * 2 + spaceIndentCount_;
continuationIndentStack->emplace_back(currIndent);
if (updateParenStack)
if (updateParenStack) {
parenIndentStack->emplace_back(previousIndent);
}
return;
}
@@ -1387,9 +1412,10 @@ void ASBeautifier::registerContinuationIndent(const std::string& line, int i, in
continuationIndentCount = minIndent + spaceIndentCount_;
// this is not done for an in-statement array
int multiplier = isInAssignment ? 1 : 2; // GL16 - no multiply in assignments
if (continuationIndentCount > maxContinuationIndent
&& !(prevNonLegalCh == '=' && currentNonLegalCh == '{'))
continuationIndentCount = indentLength /* * 2*/ + spaceIndentCount_; // GH16
continuationIndentCount = indentLength * multiplier + spaceIndentCount_;
if (!continuationIndentStack->empty()
&& continuationIndentCount < continuationIndentStack->back())
@@ -1406,7 +1432,7 @@ void ASBeautifier::registerContinuationIndent(const std::string& line, int i, in
/**
* Register a continuation indent for a class header or a class initializer colon.
*/
void ASBeautifier::registerContinuationIndentColon(const std::string& line, int i, int tabIncrementIn)
void ASBeautifier::registerContinuationIndentColon(std::string_view line, int i, int tabIncrementIn)
{
assert(line[i] == ':');
assert(isInClassInitializer || isInClassHeaderTab);
@@ -1432,7 +1458,7 @@ void ASBeautifier::registerContinuationIndentColon(const std::string& line, int
*/
std::pair<int, int> ASBeautifier::computePreprocessorIndent()
{
computePreliminaryIndentation();
computePreliminaryIndentation("");
std::pair<int, int> entry(indentCount, spaceIndentCount);
if (!headerStack->empty()
&& entry.first > 0
@@ -1448,7 +1474,7 @@ std::pair<int, int> ASBeautifier::computePreprocessorIndent()
* get distance to the next non-white space, non-comment character in the line.
* if no such character exists, return the length remaining to the end of the line.
*/
int ASBeautifier::getNextProgramCharDistance(const std::string& line, int i) const
int ASBeautifier::getNextProgramCharDistance(std::string_view line, int i) const
{
bool inComment = false;
int remainingCharNum = line.length() - i;
@@ -1521,7 +1547,7 @@ int ASBeautifier::convertTabToSpaces(int i, int tabIncrementIn) const
* @return the trimmed line.
* @param str the line to trim.
*/
std::string ASBeautifier::trim(const std::string& str) const
std::string ASBeautifier::trim(std::string_view str) const
{
int start = 0;
int end = str.length() - 1;
@@ -1546,15 +1572,14 @@ std::string ASBeautifier::trim(const std::string& str) const
* @return the trimmed line.
* @param str the line to trim.
*/
std::string ASBeautifier::rtrim(const std::string& str) const
std::string ASBeautifier::rtrim(std::string_view str) const
{
size_t len = str.length();
size_t end = str.find_last_not_of(" \t");
if (end == std::string::npos
|| end == len - 1)
return str;
std::string returnStr(str, 0, end + 1);
return returnStr;
return std::string(str);
return std::string(str.substr(0, end + 1));
}
/**
@@ -1684,7 +1709,7 @@ void ASBeautifier::initTempStacksContainer(std::vector<std::vector<const std::st
*
* @return true if line ends with a comma, otherwise false.
*/
bool ASBeautifier::statementEndsWithComma(const std::string& line, int index) const
bool ASBeautifier::statementEndsWithComma(std::string_view line, int index) const
{
assert(line[index] == '=');
@@ -1765,7 +1790,7 @@ bool ASBeautifier::statementEndsWithComma(const std::string& line, int index) co
*
* @return is before a line-end comment.
*/
bool ASBeautifier::isLineEndComment(const std::string& line, int startPos) const
bool ASBeautifier::isLineEndComment(std::string_view line, int startPos) const
{
assert(line.compare(startPos, 2, "/*") == 0);
@@ -1785,7 +1810,7 @@ bool ASBeautifier::isLineEndComment(const std::string& line, int startPos) const
*
* @return is the index to the previous word (the in statement indent).
*/
int ASBeautifier::getContinuationIndentAssign(const std::string& line, size_t currPos) const
int ASBeautifier::getContinuationIndentAssign(std::string_view line, size_t currPos) const
{
assert(line[currPos] == '=');
@@ -1813,7 +1838,7 @@ int ASBeautifier::getContinuationIndentAssign(const std::string& line, size_t cu
*
* @return is the indent to the second word on the line (the in statement indent).
*/
int ASBeautifier::getContinuationIndentComma(const std::string& line, size_t currPos) const
int ASBeautifier::getContinuationIndentComma(std::string_view line, size_t currPos) const
{
assert(line[currPos] == ',');
@@ -1874,10 +1899,10 @@ std::string ASBeautifier::getNextWord(const std::string& line, size_t currPos) c
*
* @return is true or false.
*/
bool ASBeautifier::isIndentedPreprocessor(const std::string& line, size_t currPos) const
bool ASBeautifier::isIndentedPreprocessor(std::string_view line, size_t currPos) const
{
assert(line[0] == '#');
std::string nextWord = getNextWord(line, currPos);
std::string nextWord = getNextWord(std::string(line), currPos);
if (nextWord == "region" || nextWord == "endregion")
return true;
// is it #pragma omp
@@ -1908,7 +1933,7 @@ bool ASBeautifier::isIndentedPreprocessor(const std::string& line, size_t currPo
break;
}
// check for "pragma omp"
std::string word = line.substr(start, end - start);
std::string_view word = line.substr(start, end - start);
if (word == "omp" || word == "region" || word == "endregion")
return true;
}
@@ -1920,7 +1945,7 @@ bool ASBeautifier::isIndentedPreprocessor(const std::string& line, size_t currPo
*
* @return is true or false.
*/
bool ASBeautifier::isPreprocessorConditionalCplusplus(const std::string& line) const
bool ASBeautifier::isPreprocessorConditionalCplusplus(std::string_view line) const
{
std::string preproc = trim(line.substr(1));
if (preproc.compare(0, 5, "ifdef") == 0 && getNextWord(preproc, 4) == "__cplusplus")
@@ -1952,7 +1977,7 @@ bool ASBeautifier::isPreprocessorConditionalCplusplus(const std::string& line) c
*
* @return is true or false.
*/
bool ASBeautifier::isInPreprocessorUnterminatedComment(const std::string& line)
bool ASBeautifier::isInPreprocessorUnterminatedComment(std::string_view line)
{
if (!isInPreprocessorComment)
{
@@ -1987,7 +2012,7 @@ int ASBeautifier::getBeautifierFileType() const
/**
* Process preprocessor statements and update the beautifier stacks.
*/
void ASBeautifier::processPreprocessor(const std::string& preproc, const std::string& line)
void ASBeautifier::processPreprocessor(std::string_view preproc, std::string_view line)
{
// When finding a multi-lined #define statement, the original beautifier
// 1. sets its isInDefineDefinition flag
@@ -2077,7 +2102,7 @@ void ASBeautifier::processPreprocessor(const std::string& preproc, const std::st
// Compute the preliminary indentation based on data in the headerStack
// and data from previous lines.
// Update the class variable indentCount.
void ASBeautifier::computePreliminaryIndentation()
void ASBeautifier::computePreliminaryIndentation(std::string_view line)
{
indentCount = 0;
spaceIndentCount = 0;
@@ -2105,10 +2130,12 @@ void ASBeautifier::computePreliminaryIndentation()
|| (*headerStack)[i] == &AS_THROWS
|| (*headerStack)[i] == &AS_STATIC))
++indentCount;
} else {
//GL37
if (!(i > 0 && (*headerStack)[i - 1] != &AS_OPEN_BRACE
&& (*headerStack)[i] == &AS_OPEN_BRACE))
++indentCount;
}
else if (!(i > 0 && (*headerStack)[i - 1] != &AS_OPEN_BRACE
&& (*headerStack)[i] == &AS_OPEN_BRACE))
++indentCount;
if (!isJavaStyle() && !namespaceIndent && i > 0
&& ((*headerStack)[i - 1] == &AS_NAMESPACE
@@ -2134,6 +2161,24 @@ void ASBeautifier::computePreliminaryIndentation()
isInSwitch = true;
}
// GL26 check if line is a label.... do not indent
//std::cerr << "line "<<line<< "\n";
/*
if (!blockIndent) {
size_t lastCharPos = line.find_last_not_of(" \t");
if ( isCStyle()
&& line[lastCharPos] == ':'
) {
if (labelIndent)
--indentCount; // unindent label by one indent
else
indentCount = 0;
}
} */
} // end of for loop
if (isInClassHeader)
@@ -2321,7 +2366,7 @@ int ASBeautifier::adjustIndentCountForBreakElseIfComments() const
* Extract a preprocessor statement without the #.
* If a error occurs an empty std::string is returned.
*/
std::string ASBeautifier::extractPreprocessorStatement(const std::string& line) const
std::string ASBeautifier::extractPreprocessorStatement(std::string_view line) const
{
std::string preproc;
size_t start = line.find_first_not_of("#/ \t");
@@ -2334,7 +2379,7 @@ std::string ASBeautifier::extractPreprocessorStatement(const std::string& line)
return preproc;
}
void ASBeautifier::adjustObjCMethodDefinitionIndentation(const std::string& line_)
void ASBeautifier::adjustObjCMethodDefinitionIndentation(std::string_view line_)
{
// register indent for Objective-C continuation line
if (line_.length() > 0
@@ -2365,7 +2410,7 @@ void ASBeautifier::adjustObjCMethodDefinitionIndentation(const std::string& line
}
}
void ASBeautifier::adjustObjCMethodCallIndentation(const std::string& line_)
void ASBeautifier::adjustObjCMethodCallIndentation(std::string_view line_)
{
static int keywordIndentObjCMethodAlignment = 0;
if (shouldAlignMethodColon && objCColonAlignSubsequent != -1)
@@ -2442,7 +2487,7 @@ void ASBeautifier::clearObjCMethodDefinitionAlignment()
* Find the first alignment colon on a line.
* Ternary operators (?) are bypassed.
*/
int ASBeautifier::findObjCColonAlignment(const std::string& line) const
int ASBeautifier::findObjCColonAlignment(std::string_view line) const
{
bool haveTernary = false;
for (size_t i = 0; i < line.length(); i++)
@@ -2500,7 +2545,7 @@ int ASBeautifier::findObjCColonAlignment(const std::string& line) const
* If it cannot be aligned indentLength is returned and a new colon
* position is calculated.
*/
int ASBeautifier::computeObjCColonAlignment(const std::string& line, int colonAlignPosition) const
int ASBeautifier::computeObjCColonAlignment(std::string_view line, int colonAlignPosition) const
{
int colonPosition = findObjCColonAlignment(line);
if (colonPosition < 0 || colonPosition > colonAlignPosition)
@@ -2514,7 +2559,7 @@ int ASBeautifier::computeObjCColonAlignment(const std::string& line, int colonAl
* Use for now and see what happens.
* Most programmers will probably use align-method-colon anyway.
*/
int ASBeautifier::getObjCFollowingKeyword(const std::string& line, int bracePos) const
int ASBeautifier::getObjCFollowingKeyword(std::string_view line, int bracePos) const
{
assert(line[bracePos] == '[');
size_t firstText = line.find_first_not_of(" \t", bracePos + 1);
@@ -2554,11 +2599,11 @@ int ASBeautifier::getObjCFollowingKeyword(const std::string& line, int bracePos)
* The indentCount is NOT included
* Needed to compute an accurate alignment.
*/
std::string ASBeautifier::getIndentedSpaceEquivalent(const std::string& line_) const
std::string ASBeautifier::getIndentedSpaceEquivalent(std::string_view line_) const
{
std::string spaceIndent;
spaceIndent.append(spaceIndentCount, ' ');
std::string convertedLine = spaceIndent + line_;
std::string convertedLine = spaceIndent + std::string(line_);
for (size_t i = spaceIndent.length(); i < convertedLine.length(); i++)
{
if (convertedLine[i] == '\t')
@@ -2602,7 +2647,7 @@ bool ASBeautifier::isTopLevel() const
/**
* Parse the current line to update indentCount and spaceIndentCount.
*/
void ASBeautifier::parseCurrentLine(const std::string& line)
void ASBeautifier::parseCurrentLine(std::string_view line)
{
bool isInLineComment = false;
bool isInOperator = false;
@@ -2614,10 +2659,12 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
char ch = ' ';
int tabIncrementIn = 0;
if (isInQuote
&& !haveLineContinuationChar
&& !isInVerbatimQuote
&& !isInAsm)
&& !isInAsm
&& !isInMultiLineString)
isInQuote = false; // missing closing quote
haveLineContinuationChar = false;
@@ -2629,6 +2676,8 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
if (isInBeautifySQL)
continue;
bool isTripleQuoteDelimiter = (isJavaStyle() || isSharpStyle() ) && line.length() > i + 2 && line[i + 1] == '"' && line[i + 2 ] == '"';
// handle special characters (i.e. backslash+character such as \n, \t, ...)
if (isInQuote && !isInVerbatimQuote)
{
@@ -2674,15 +2723,18 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
&& (ch == '"'
|| (ch == '\'' && !isDigitSeparator(line, i))))
{
if (!isInQuote)
if (!isInQuote && !isInMultiLineString)
{
quoteChar = ch;
isInQuote = true;
isInMultiLineString = isTripleQuoteDelimiter;
char prevCh = i > 0 ? line[i - 1] : ' ';
char prevPrevCh = i > 1 ? line[i - 2] : ' ';
// GL 32
// https://sourceforge.net/p/astyle/bugs/535/
if (isCStyle() && prevCh == 'R' && !(isalpha(prevNonSpaceCh) || prevNonSpaceCh == '(' ))
if (isCStyle() && prevCh == 'R' && !isalpha(prevPrevCh) && !(isalpha(prevNonSpaceCh) ))
{
int parenPos = line.find('(', i);
if (parenPos != -1)
@@ -2723,6 +2775,13 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
}
}
}
else if (isTripleQuoteDelimiter && isInMultiLineString)
{
isInMultiLineString = false;
isInQuote = false;
isContinuation = true;
continue;
}
else if (quoteChar == ch)
{
isInQuote = false;
@@ -2885,8 +2944,10 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
}
// handle parentheses
if (ch == '(' || ch == '[' || ch == ')' || ch == ']')
if ((ch == '(' && !isInInitializerList) || ch == '[' || ch == ')' || ch == ']')
{
// GL28 xx
if (ch == '(' || ch == '[')
{
isInOperator = false;
@@ -2925,7 +2986,7 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
if ( !isLegalNameChar(prevNonSpaceCh)
&& prevNonSpaceCh != ']'
&& prevNonSpaceCh != ')'
&& prevNonSpaceCh != '*' // GH #11
&& prevNonSpaceCh != '*' // GL #11
//&& line.find(AS_AUTO, 0 ) == std::string::npos
)
{
@@ -3024,6 +3085,9 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
isBlockOpener = true;
}
// GL28 fix initializer lists like x({a.x=0;})
isInInitializerList = isCStyle() && isBlockOpener && (prevNonSpaceCh=='(' || prevNonSpaceCh=='=');
if (!isBlockOpener && currentHeader != nullptr)
{
for (const std::string* const nonParenHeader : *nonParenHeaders)
@@ -3160,7 +3224,7 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
else if (isSharpStyle()
&& (newHeader == &AS_GET || newHeader == &AS_SET))
{
if (getNextWord(line, i + (*newHeader).length()) == "is")
if (getNextWord(std::string(line), i + (*newHeader).length()) == "is")
newHeader = nullptr;
}
else if (newHeader == &AS_USING
@@ -3501,6 +3565,8 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
// handle ends of statements
if ((ch == ';' && parenDepth == 0) || ch == '}')
{
isInAssignment = isInInitializerList = false;
if (ch == '}')
{
@@ -3746,7 +3812,7 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
}
// bypass the entire name for all others
std::string name = getCurrentWord(line, i);
std::string_view name = getCurrentWord(line, i);
i += name.length() - 1;
continue;
}
@@ -3759,11 +3825,11 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
&& !isWhiteSpace(line[i + 1])
&& isCharPotentialHeader(line, i + 1))
{
std::string curWord = getCurrentWord(line, i + 1);
std::string_view curWord = getCurrentWord(line, i + 1);
if (curWord == AS_INTERFACE || curWord == AS_AUTORELEASEPOOL)
{
isInObjCInterface = true;
std::string name = '@' + curWord;
std::string name = '@' + std::string(curWord);
i += name.length() - 1;
continue;
}
@@ -3781,7 +3847,7 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
--indentCount;
if (modifierIndent)
spaceIndentCount += (indentLength / 2);
std::string name = '@' + curWord;
std::string name = '@' + std::string(curWord);
i += name.length() - 1;
continue;
}
@@ -3791,7 +3857,7 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
popLastContinuationIndent();
spaceIndentCount = 0;
isInObjCMethodDefinition = false;
std::string name = '@' + curWord;
std::string name = '@' + std::string(curWord);
i += name.length() - 1;
continue;
}
@@ -3849,12 +3915,36 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
// For C++ input/output, operator<<, >> and . method calls should be
// aligned, if we are not in a statement already and
// also not in the "operator<<(...)" header line
// GL28: method calls have to contain only alphanumeric identifier
size_t openParenPos = line.find(AS_OPEN_PAREN, i);
std::string methodName = getNextWord(std::string(line), i);
size_t methodNameEndPos = i + methodName.length() + 1;
size_t firstCharAfterMethod = line.substr(i + methodName.length() + 1).find_first_not_of(" \t");
if (firstCharAfterMethod != std::string::npos)
{
methodNameEndPos += firstCharAfterMethod;
}
size_t firstCharOfLine = line.find_first_not_of(" \t");
bool lineStartsWithDot = false;
if (firstCharOfLine != std::string::npos)
{
lineStartsWithDot = line[firstCharOfLine] == '.';
}
// GL28: do not mixup template closing ">>" with IO operator
std::string searchTemplatePattern = std::string(line).substr(0, i);
size_t countLS = std::count_if( searchTemplatePattern.begin(), searchTemplatePattern.end(), []( char c ){return c =='<';});
if (!isInOperator
&& continuationIndentStack->empty()
&& isCStyle()
&& (foundNonAssignmentOp == &AS_GR_GR
|| foundNonAssignmentOp == &AS_LS_LS
|| (foundNonAssignmentOp == &AS_DOT && line.find(AS_OPEN_PAREN, i) != std::string::npos)))
&& !lineStartsWithDot
&& ( (foundNonAssignmentOp == &AS_GR_GR && countLS < 2 )
|| foundNonAssignmentOp == &AS_LS_LS
|| (foundNonAssignmentOp == &AS_DOT && openParenPos == methodNameEndPos)))
{
// this will be true if the line begins with the operator
if (i < foundNonAssignmentOp->length() && spaceIndentCount == 0)
@@ -3866,6 +3956,9 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
else if (foundAssignmentOp != nullptr)
{
isInAssignment = true;
foundPreCommandHeader = false; // clears this for array assignments
foundPreCommandMacro = false;
+11 -12
View File
@@ -188,7 +188,7 @@ void ASEnhancer::convertSpaceIndentToForceTab(std::string& line) const
* @param caseIndex the line index of the case statement.
* @return the line index of the colon.
*/
size_t ASEnhancer::findCaseColon(const std::string& line, size_t caseIndex) const
size_t ASEnhancer::findCaseColon(std::string_view line, size_t caseIndex) const
{
size_t i = caseIndex;
bool isInQuote_ = false;
@@ -276,9 +276,9 @@ int ASEnhancer::indentLine(std::string& line, int indent) const
* @param index the current line index.
* @return true if a hit.
*/
bool ASEnhancer::isBeginDeclareSectionSQL(const std::string& line, size_t index) const
bool ASEnhancer::isBeginDeclareSectionSQL(std::string_view line, size_t index) const
{
std::string word;
size_t hits = 0;
size_t i;
for (i = index; i < line.length(); i++)
@@ -290,8 +290,8 @@ bool ASEnhancer::isBeginDeclareSectionSQL(const std::string& line, size_t index)
break;
if (!isCharPotentialHeader(line, i))
continue;
word = getCurrentWord(line, i);
for (char& character : word)
std::string_view word = getCurrentWord(line, i);
for (char character : word)
character = (char) toupper(character);
if (word == "EXEC" || word == "SQL")
{
@@ -325,9 +325,8 @@ bool ASEnhancer::isBeginDeclareSectionSQL(const std::string& line, size_t index)
* @param index the current line index.
* @return true if a hit.
*/
bool ASEnhancer::isEndDeclareSectionSQL(const std::string& line, size_t index) const
bool ASEnhancer::isEndDeclareSectionSQL(std::string_view line, size_t index) const
{
std::string word;
size_t hits = 0;
size_t i;
for (i = index; i < line.length(); i++)
@@ -339,8 +338,8 @@ bool ASEnhancer::isEndDeclareSectionSQL(const std::string& line, size_t index) c
break;
if (!isCharPotentialHeader(line, i))
continue;
word = getCurrentWord(line, i);
for (char& character : word)
std::string_view word = getCurrentWord(line, i);
for (char character : word)
character = (char) toupper(character);
if (word == "EXEC" || word == "SQL")
{
@@ -374,7 +373,7 @@ bool ASEnhancer::isEndDeclareSectionSQL(const std::string& line, size_t index) c
* @return false = one-line brace has not been reached.
* true = one-line brace has been reached.
*/
bool ASEnhancer::isOneLineBlockReached(const std::string& line, int startChar) const
bool ASEnhancer::isOneLineBlockReached(std::string_view line, int startChar) const
{
assert(line[startChar] == '{');
@@ -619,7 +618,7 @@ void ASEnhancer::parseCurrentLine(std::string& line, bool isInPreprocessor, bool
// bypass the entire word
if (isPotentialKeyword)
{
std::string name = getCurrentWord(line, i);
std::string_view name = getCurrentWord(line, i);
i += name.length() - 1;
}
continue;
@@ -712,7 +711,7 @@ size_t ASEnhancer::processSwitchBlock(std::string& line, size_t index)
}
if (isPotentialKeyword)
{
std::string name = getCurrentWord(line, i); // bypass the entire name
std::string_view name = getCurrentWord(line, i); // bypass the entire name
i += name.length() - 1;
}
return i;
+261 -110
View File
@@ -42,10 +42,12 @@ ASFormatter::ASFormatter()
referenceAlignment = REF_SAME_AS_PTR;
objCColonPadMode = COLON_PAD_NO_CHANGE;
lineEnd = LINEEND_DEFAULT;
squeezeEmptyLineNum = std::string::npos;
maxCodeLength = std::string::npos;
isInStruct = false;
shouldPadCommas = false;
shouldPadOperators = false;
negationPadMode = NEGATION_PAD_NO_CHANGE;
shouldPadParensOutside = false;
shouldPadFirstParen = false;
shouldPadEmptyParens = false;
@@ -76,7 +78,7 @@ ASFormatter::ASFormatter()
shouldAttachReturnTypeDecl = false;
shouldBreakElseIfs = false;
shouldBreakLineAfterLogical = false;
shouldAddBraces = false;
shouldAddBraces = 0;
shouldAddOneLineBraces = false;
shouldRemoveBraces = false;
shouldPadMethodColon = false;
@@ -89,6 +91,8 @@ ASFormatter::ASFormatter()
shouldPadBracketsOutside = false;
shouldPadBracketsInside = false;
shouldUnPadBrackets = false;
isInMultlineStatement = false;
isInExplicitBlock = 0;
// initialize ASFormatter member std::vectors
formatterFileType = INVALID_TYPE; // reset to an invalid type
@@ -175,6 +179,7 @@ void ASFormatter::init(ASSourceIterator* si)
clearFormattedLineSplitPoints();
currentHeader = nullptr;
previousHeader = nullptr;
currentLine = "";
readyFormattedLine = "";
formattedLine = "";
@@ -203,6 +208,7 @@ void ASFormatter::init(ASSourceIterator* si)
templateDepth = 0;
squareBracketCount = 0;
parenthesesCount = 0;
closingBracesCount = 0;
squeezeEmptyLineCount = 0;
runInIndentChars = 0;
@@ -312,6 +318,8 @@ void ASFormatter::init(ASSourceIterator* si)
isInHeader = false;
isInCase = false;
isInAllocator = false;
isInMultlineStatement = false;
isInExplicitBlock = 0;
isFirstPreprocConditional = false;
processedFirstConditional = false;
@@ -412,7 +420,7 @@ void ASFormatter::fixOptionVariableConflicts()
else if (formattingStyle == STYLE_1TBS)
{
setBraceFormatMode(LINUX_MODE);
setAddBracesMode(true);
setAddBracesMode(1);
setRemoveBracesMode(false);
}
else if (formattingStyle == STYLE_GOOGLE)
@@ -450,7 +458,7 @@ void ASFormatter::fixOptionVariableConflicts()
// only shouldAddBraces should be set to true
if (shouldAddOneLineBraces)
{
shouldAddBraces = true;
shouldAddBraces = 1;
shouldAddOneLineBraces = false;
}
}
@@ -868,6 +876,7 @@ std::string ASFormatter::nextLine()
if (passedSemicolon) // need to break the formattedLine
{
isInAllocator = false; // GH16
isInMultlineStatement = false;
passedSemicolon = false;
if (parenStack->back() == 0 && !isCharImmediatelyPostComment && currentChar != ';') // allow ;;
{
@@ -1060,6 +1069,7 @@ std::string ASFormatter::nextLine()
// handle braces
if (currentChar == '{' || currentChar == '}')
{
// if appendOpeningBrace this was already done for the original brace
if (currentChar == '{' && !appendOpeningBrace)
{
@@ -1084,6 +1094,9 @@ std::string ASFormatter::nextLine()
needHeaderOpeningBrace = false;
shouldKeepLineUnbroken = false;
returnTypeChecked = false;
isInExplicitBlock++;
objCColonAlign = 0;
methodBreakCharNum = std::string::npos;
@@ -1122,6 +1135,8 @@ std::string ASFormatter::nextLine()
shouldKeepLineUnbroken = false;
squareBracketCount = 0;
isInAllocator = false;
isInMultlineStatement = false;
isInExplicitBlock--;
if (braceTypeStack->size() > 1)
{
@@ -1137,6 +1152,7 @@ std::string ASFormatter::nextLine()
if (!preBraceHeaderStack->empty())
{
previousHeader = currentHeader;
currentHeader = preBraceHeaderStack->back();
preBraceHeaderStack->pop_back();
}
@@ -1323,7 +1339,7 @@ std::string ASFormatter::nextLine()
isAppendPostBlockEmptyLineRequested = false;
}
const std::string* previousHeader = currentHeader;
previousHeader = currentHeader;
currentHeader = newHeader;
needHeaderOpeningBrace = true;
@@ -1409,6 +1425,7 @@ std::string ASFormatter::nextLine()
}
}
// #569
if (shouldBreakBlocks
&& isOkToBreakBlock(braceTypeStack->back())
&& !isHeaderInMultiStatementLine)
@@ -1519,7 +1536,7 @@ std::string ASFormatter::nextLine()
passedSemicolon = true;
}
//is set in struct case? #518
//is set in struct case? #518 #569
if (shouldBreakBlocks
&& currentHeader != nullptr
&& currentHeader != &AS_CASE
@@ -1602,8 +1619,9 @@ std::string ASFormatter::nextLine()
if (isPotentialHeader && !isInTemplate)
{
if (findKeyword(currentLine, charNum, AS_NEW)
|| findKeyword(currentLine, charNum, AS_DELETE))
//GL30
if (!isGHCStyle() && (findKeyword(currentLine, charNum, AS_NEW)
|| findKeyword(currentLine, charNum, AS_DELETE)))
{
isInPotentialCalculation = false;
isImmediatelyPostNewDelete = true;
@@ -1736,14 +1754,14 @@ std::string ASFormatter::nextLine()
isSharpDelegate = true;
// append the entire name
std::string name = getCurrentWord(currentLine, charNum);
std::string_view name = getCurrentWord(currentLine, charNum);
// must pad the 'and' and 'or' operators if required
if (name == "and" || name == "or")
{
if (shouldPadOperators && previousNonWSChar != ':')
{
appendSpacePad();
appendOperator(name);
appendOperator(std::string(name));
goForward(name.length() - 1);
if (!isBeforeAnyComment()
&& !(currentLine.compare(charNum + 1, 1, AS_SEMICOLON) == 0)
@@ -1752,13 +1770,13 @@ std::string ASFormatter::nextLine()
}
else
{
appendOperator(name);
appendOperator(std::string(name));
goForward(name.length() - 1);
}
}
else
{
appendSequence(name);
appendSequence(std::string(name));
goForward(name.length() - 1);
}
@@ -1879,7 +1897,7 @@ std::string ASFormatter::nextLine()
continue;
}
if (shouldPadOperators && newHeader != nullptr && !isOperatorPaddingDisabled())
if ((shouldPadOperators || negationPadMode!=NEGATION_PAD_NO_CHANGE) && newHeader != nullptr && !isOperatorPaddingDisabled())
{
padOperators(newHeader);
continue;
@@ -1959,7 +1977,9 @@ std::string ASFormatter::nextLine()
continue;
}
if ((currentChar == '[' || currentChar == ']' ) && (shouldPadBracketsOutside || shouldPadBracketsInside || shouldUnPadBrackets) )
//GL31
bool isDoubleOpenBrackets = isGHCStyle() && currentChar=='[' && peekNextChar() == '[';
if ((currentChar == '[' || currentChar == ']' ) && (shouldPadBracketsOutside || shouldPadBracketsInside || shouldUnPadBrackets) && !isDoubleOpenBrackets)
{
padParensOrBrackets('[', ']', shouldPadBracketsOutside, shouldPadBracketsInside, shouldUnPadBrackets, false);
continue;
@@ -2057,12 +2077,13 @@ void ASFormatter::setFormattingStyle(FormatStyle style)
/**
* set the add braces mode.
* options:
* true braces added to headers for single line statements.
* false braces NOT added to headers for single line statements.
* 2 braces added to headers for (nested) single line statements.
* 1 braces added to headers for single line statements.
* 0 braces NOT added to headers for single line statements.
*
* @param state the add braces state.
*/
void ASFormatter::setAddBracesMode(bool state)
void ASFormatter::setAddBracesMode(int state)
{
shouldAddBraces = state;
}
@@ -2077,7 +2098,7 @@ void ASFormatter::setAddBracesMode(bool state)
*/
void ASFormatter::setAddOneLineBracesMode(bool state)
{
shouldAddBraces = state;
shouldAddBraces = state ? 1 : 0;
shouldAddOneLineBraces = state;
}
@@ -2210,6 +2231,15 @@ void ASFormatter::setOperatorPaddingMode(bool state)
shouldPadOperators = state;
}
/**
* set negation padding mode.
* @param state the padding mode.
*/
void ASFormatter::setNegationPaddingMode(NegationPaddingMode mode)
{
negationPadMode = mode;
}
/**
* set parenthesis outside padding mode.
* options:
@@ -2799,6 +2829,12 @@ bool ASFormatter::getNextLine(bool emptyLineWasDeleted /*false*/)
if (currentLine.length() == 0)
{
//#574 avoid deletion of empüty lines after continuation
if (!isInComment && previousNonWSChar == '\\')
{
return false;
}
isInContinuedPreProc = false;
currentLine = std::string(" "); // a null is inserted if this is not done
}
@@ -3024,7 +3060,7 @@ void ASFormatter::appendChar(char ch, bool canBreakLine)
* @param sequence the sequence to append.
* @param canBreakLine if true, a registered line-break
*/
void ASFormatter::appendSequence(const std::string& sequence, bool canBreakLine)
void ASFormatter::appendSequence(std::string_view sequence, bool canBreakLine)
{
if (canBreakLine && isInLineBreak)
breakLine();
@@ -3040,7 +3076,7 @@ void ASFormatter::appendSequence(const std::string& sequence, bool canBreakLine)
* @param sequence the sequence to append.
* @param canBreakLine if true, a registered line-break
*/
void ASFormatter::appendOperator(const std::string& sequence, bool canBreakLine)
void ASFormatter::appendOperator(std::string_view sequence, bool canBreakLine)
{
if (canBreakLine && isInLineBreak)
breakLine();
@@ -3235,7 +3271,7 @@ BraceType ASFormatter::getBraceType()
return returnVal;
}
bool ASFormatter::isNumericVariable(const std::string& word) const
bool ASFormatter::isNumericVariable(std::string_view word) const
{
if (word == "bool"
|| word == "int"
@@ -3247,11 +3283,7 @@ bool ASFormatter::isNumericVariable(const std::string& word) const
|| word == "float"
|| (word.length() >= 4 // check end of word for _t
&& word.compare(word.length() - 2, 2, "_t") == 0)
// removed release 3.1
// || word == "Int32"
// || word == "UInt32"
// || word == "Int64"
// || word == "UInt64"
|| word == "BOOL"
|| word == "DWORD"
|| word == "HWND"
@@ -3278,19 +3310,10 @@ bool ASFormatter::isClassInitializer() const
// this should be similar to ASBeautifier::parseCurrentLine()
bool foundClassInitializer = false;
if (foundQuestionMark)
if (foundQuestionMark || parenStack->back() > 0 || isInEnum)
{
// do nothing special
}
else if (parenStack->back() > 0)
{
// found a 'for' loop or an objective-C statement
// so do nothing special
}
else if (isInEnum)
{
// found an enum with a base-type
}
else if (isCStyle()
&& !isInCase
&& (previousCommandChar == ')' || foundPreCommandHeader))
@@ -3306,7 +3329,7 @@ bool ASFormatter::isClassInitializer() const
*
* @return whether line is empty
*/
bool ASFormatter::isEmptyLine(const std::string& line) const
bool ASFormatter::isEmptyLine(std::string_view line) const
{
return line.find_first_not_of(" \t") == std::string::npos;
}
@@ -3373,8 +3396,14 @@ bool ASFormatter::isPointerOrReference() const
return false;
if ((foundCastOperator && nextChar == '>')
|| isPointerOrReferenceVariable(lastWord))
|| isPointerOrReferenceVariable(lastWord)) {
return true;
}
if (pointerAlignment == PTR_ALIGN_TYPE
&& !isPointerOrReferenceVariable(lastWord)) {
return false;
}
if (isInClassInitializer
&& previousNonWSChar != '('
@@ -3402,6 +3431,7 @@ bool ASFormatter::isPointerOrReference() const
return false;
return true;
}
if (nextChar == '*'
|| previousNonWSChar == '='
|| previousNonWSChar == '('
@@ -3411,8 +3441,10 @@ bool ASFormatter::isPointerOrReference() const
|| isCharImmediatelyPostTemplate
|| currentHeader == &AS_CATCH
|| currentHeader == &AS_FOREACH
|| currentHeader == &AS_QFOREACH)
|| currentHeader == &AS_QFOREACH) {
return true;
}
if (isBraceType(braceTypeStack->back(), ARRAY_TYPE)
&& isLegalNameChar(lastWord[0])
@@ -3435,8 +3467,10 @@ bool ASFormatter::isPointerOrReference() const
&& followingOperator != &AS_MULT
&& followingOperator != &AS_BIT_AND)
{
if (followingOperator == &AS_ASSIGN || followingOperator == &AS_COLON)
if (followingOperator == &AS_ASSIGN || followingOperator == &AS_COLON) {
return true;
}
return false;
}
@@ -3531,6 +3565,10 @@ bool ASFormatter::isDereferenceOrAddressOf() const
return false;
}
if (previousNonWSChar == '(' && currentChar == '&' && pointerAlignment == PTR_ALIGN_TYPE) {
return true;
}
// check first char on the line
if (charNum == (int) currentLine.find_first_not_of(" \t")
&& (isBraceType(braceTypeStack->back(), COMMAND_TYPE)
@@ -3557,12 +3595,12 @@ bool ASFormatter::isDereferenceOrAddressOf() const
std::string lastWord = getPreviousWord(currentLine, charNum);
if (lastWord == "else" || lastWord == "delete")
return true;
if (isPointerOrReferenceVariable(lastWord))
return false;
bool isDA = (!(isLegalNameChar(previousNonWSChar) || previousNonWSChar == '>') // TODO GH14
|| (nextText.length() > 0 && !isLegalNameChar(nextText[0]) && nextText[0] != '/')
|| (ispunct((unsigned char)previousNonWSChar) && previousNonWSChar != '.') // TODO GH14
|| isCharImmediatelyPostReturn);
|| isCharImmediatelyPostReturn
|| !isPointerOrReferenceVariable(lastWord));
return isDA;
}
@@ -3619,21 +3657,31 @@ bool ASFormatter::isPointerOrReferenceCentered() const
*
* @return whether word is a pointer or reference variable.
*/
bool ASFormatter::isPointerOrReferenceVariable(const std::string& word) const
bool ASFormatter::isPointerOrReferenceVariable(std::string_view word) const
{
assert(currentChar == '*' || currentChar == '&' || currentChar == '^');
bool retval = false;
if (word == "char"
|| word == "std::string"
|| word == "String"
|| word == "NSString"
|| word == "int"
|| word == "void"
|| (word.length() >= 6 // check end of word for _t
&& word.compare(word.length() - 2, 2, "_t") == 0)
|| word == "INT"
|| word == "VOID")
retval = true;
// to avoid problem with multiplications - we need LSP
for (char c: word){
if (isLegalNameChar(c)) {
retval = true;
break;
}
}
if (currentChar == '&' &&
(currentHeader == &AS_IF
|| currentHeader == &AS_ELSE
|| currentHeader == &AS_FOR
|| currentHeader == &AS_WHILE
|| currentHeader == &AS_DO)) {
retval = false;
}
if (pointerAlignment == PTR_ALIGN_TYPE) {
return retval;
}
// check for C# object type "x is std::string"
if (retval && isSharpStyle())
@@ -3646,6 +3694,7 @@ bool ASFormatter::isPointerOrReferenceVariable(const std::string& word) const
if (prevWord == "is")
retval = false;
}
return retval;
}
@@ -3654,7 +3703,7 @@ bool ASFormatter::isPointerOrReferenceVariable(const std::string& word) const
*
* @return true if a pointer *.
*/
bool ASFormatter::isPointerToPointer(const std::string& line, int currPos) const
bool ASFormatter::isPointerToPointer(std::string_view line, int currPos) const
{
assert(line[currPos] == '*' && peekNextChar() == '*');
if ((int) line.length() > currPos + 1 && line[currPos + 1] == '*')
@@ -3733,13 +3782,19 @@ bool ASFormatter::isInSwitchStatement() const
bool ASFormatter::isInExponent() const
{
assert(currentChar == '+' || currentChar == '-');
std::string prevWord = getPreviousWord(currentLine, charNum, true);
if (charNum >= 2)
if (charNum && isDigit(prevWord[0])) {
return prevWord.find_first_not_of("0123456789.") != std::string::npos;
}
if (charNum > 2 && prevWord.size()>=2 && prevWord[0]=='0' && (prevWord[1]=='x' || prevWord[1]=='X'))
{
char prevPrevFormattedChar = currentLine[charNum - 2];
char prevFormattedChar = currentLine[charNum - 1];
return ((prevFormattedChar == 'e' || prevFormattedChar == 'E')
&& (prevPrevFormattedChar == '.' || isDigit(prevPrevFormattedChar)));
// double x = 0x1.23ffp-11;
return ((prevFormattedChar == 'e' || prevFormattedChar == 'E' || prevFormattedChar == 'p' || prevFormattedChar == 'P')
&& (prevPrevFormattedChar == '.' || std::isxdigit(prevPrevFormattedChar)));
}
return false;
}
@@ -3781,7 +3836,7 @@ bool ASFormatter::isNonInStatementArrayBrace() const
* 2 = one-line block has been reached and is followed by a comma.
* 3 = one-line block has been reached and is an empty block.
*/
int ASFormatter::isOneLineBlockReached(const std::string& line, int startChar) const
int ASFormatter::isOneLineBlockReached(std::string_view line, int startChar) const
{
assert(line[startChar] == '{');
@@ -4033,13 +4088,13 @@ bool ASFormatter::isMultiStatementLine() const
* @param firstLine the first line to check
* @return the next non-whitespace substd::string.
*/
std::string ASFormatter::peekNextText(const std::string& firstLine,
std::string ASFormatter::peekNextText(std::string_view firstLine,
bool endOnEmptyLine /*false*/,
const std::shared_ptr<ASPeekStream>& streamArg /*nullptr*/) const
{
assert(sourceIterator->getPeekStart() == 0 || streamArg != nullptr); // Borland may need != 0
bool isFirstLine = true;
std::string nextLine_ = firstLine;
std::string nextLine_(firstLine);
size_t firstChar = std::string::npos;
std::shared_ptr<ASPeekStream> stream = streamArg;
if (stream == nullptr) // Borland may need == 0
@@ -4192,16 +4247,17 @@ void ASFormatter::appendCharInsideComments()
*/
void ASFormatter::padOperators(const std::string* newOperator)
{
assert(shouldPadOperators);
assert(shouldPadOperators || negationPadMode != NEGATION_PAD_NO_CHANGE);
assert(newOperator != nullptr);
char nextNonWSChar = ASBase::peekNextChar(currentLine, charNum);
std::set<char> allowedChars = {'(', '[', '=', ',', ':', '{'};
// #566
bool shouldPad = (newOperator != &AS_SCOPE_RESOLUTION
&& newOperator != &AS_PLUS_PLUS
&& newOperator != &AS_MINUS_MINUS
&& newOperator != &AS_NOT
&& (newOperator != &AS_NOT || negationPadMode != NEGATION_PAD_NO_CHANGE) // TODO 571
&& newOperator != &AS_BIT_NOT
&& newOperator != &AS_ARROW
&& !(newOperator == &AS_COLON && !foundQuestionMark // objC methods
@@ -4239,6 +4295,7 @@ void ASFormatter::padOperators(const std::string* newOperator)
// pad before operator
if (shouldPad
&& (newOperator != &AS_NOT || (newOperator == &AS_NOT && negationPadMode == NEGATION_PAD_BEFORE ) )
&& !(newOperator == &AS_COLON
&& (!foundQuestionMark && !isInEnum) && currentHeader != &AS_FOR)
&& !(newOperator == &AS_QUESTION && isSharpStyle() // check for C# nullable type (e.g. int?)
@@ -4377,7 +4434,7 @@ void ASFormatter::formatPointerOrReferenceToType()
}
// https://sourceforge.net/p/astyle/bugs/537/
if (previousNonWSChar == ',' && currentChar != ' ')
if ((previousNonWSChar == ',' || previousNonWSChar == '[') && currentChar != ' ')
appendSpacePad();
formattedLine.append(sequenceToInsert);
@@ -4425,6 +4482,7 @@ void ASFormatter::formatPointerOrReferenceToMiddle()
else
wsBefore = charNum - wsBefore - 1;
std::string sequenceToInsert(1, currentChar);
if (currentChar == peekNextChar())
{
for (size_t i = charNum + 1; currentLine.length() > i; i++)
@@ -4440,6 +4498,7 @@ void ASFormatter::formatPointerOrReferenceToMiddle()
}
// if reference to a pointer check for conflicting alignment
else if (currentChar == '*' && peekNextChar() == '&'
&& ASBeautifier::peekNextChar(currentLine, charNum + 1) != '&'
&& (referenceAlignment == REF_ALIGN_TYPE
|| referenceAlignment == REF_ALIGN_MIDDLE
|| referenceAlignment == REF_SAME_AS_PTR))
@@ -4565,7 +4624,7 @@ void ASFormatter::formatPointerOrReferenceToName()
// if reference to a pointer align both to name
else if (currentChar == '*' && peekNextChar() == '&')
else if (currentChar == '*' && peekNextChar() == '&' && ASBeautifier::peekNextChar(currentLine, charNum + 1) != '&')
{
sequenceToInsert = "*&";
goForward(1);
@@ -5097,6 +5156,8 @@ void ASFormatter::formatOpeningBrace(BraceType braceType)
bool breakBrace = isCurrentBraceBroken();
//478
if (breakBrace)
{
if (isBeforeAnyComment() && isOkToBreakBlock(braceType) && sourceIterator->hasMoreLines())
@@ -5294,10 +5355,13 @@ void ASFormatter::formatClosingBrace(BraceType braceType)
}
else {
// GH18
// #569
isAppendPostBlockEmptyLineRequested = !(shouldBreakBlocks && shouldAttachClosingWhile)
|| currentHeader != &AS_DO;
}
} else {
isAppendPostBlockEmptyLineRequested = !currentHeader && shouldBreakBlocks;
}
}
@@ -5321,12 +5385,13 @@ void ASFormatter::formatArrayBraces(BraceType braceType, bool isOpeningArrayBrac
// is this the first opening brace in the array?
if (isOpeningArrayBrace)
{
if (braceFormatMode == ATTACH_MODE
|| braceFormatMode == LINUX_MODE)
if (braceFormatMode == ATTACH_MODE || braceFormatMode == LINUX_MODE)
{
// break an enum if mozilla
if (isBraceType(braceType, ENUM_TYPE)
&& formattingStyle == STYLE_MOZILLA)
&& formattingStyle == STYLE_MOZILLA
&& !(!shouldBreakOneLineBlocks && formattedLine.find('}' != std::string::npos) ) // GL38
)
{
isInLineBreak = true;
appendCurrentChar(); // don't attach
@@ -5769,7 +5834,7 @@ bool ASFormatter::isSharpStyleWithParen(const std::string* header) const
* firstLine must contain the start of the comment.
* return value is a pointer to the header or nullptr.
*/
const std::string* ASFormatter::checkForHeaderFollowingComment(const std::string& firstLine) const
const std::string* ASFormatter::checkForHeaderFollowingComment(std::string_view firstLine) const
{
assert(isInComment || isInLineComment);
assert(shouldBreakElseIfs || shouldBreakBlocks || isInSwitchStatement());
@@ -6399,7 +6464,9 @@ void ASFormatter::formatQuoteOpener()
isInQuote = true;
quoteChar = currentChar;
if (isCStyle() && previousChar == 'R')
char prevPrevCh = charNum > 2 ? currentLine[charNum - 2] : ' '; // GL39
if (isCStyle() && previousChar == 'R' && !isalpha(prevPrevCh))
{
int parenPos = currentLine.find('(', charNum);
if (parenPos != -1)
@@ -6493,7 +6560,7 @@ int ASFormatter::getCurrentLineCommentAdjustment()
*
* @return is the previous word or an empty std::string if none found.
*/
std::string ASFormatter::getPreviousWord(const std::string& line, int currPos) const
std::string ASFormatter::getPreviousWord(const std::string& line, int currPos, bool allowDots) const
{
// get the last legal word (may be a number)
if (currPos == 0)
@@ -6506,7 +6573,7 @@ std::string ASFormatter::getPreviousWord(const std::string& line, int currPos) c
int start; // start of the previous word
for (start = end; start > -1; start--)
{
if (!isLegalNameChar(line[start]) || line[start] == '.')
if (!isLegalNameChar(line[start]) || (!allowDots && line[start] == '.') )
break;
}
start++;
@@ -6602,14 +6669,14 @@ bool ASFormatter::addBracesToStatement()
assert(isImmediatelyPostHeader);
if (currentHeader != &AS_IF
&& currentHeader != &AS_ELSE
&& currentHeader != &AS_FOR
&& currentHeader != &AS_WHILE
&& currentHeader != &AS_DO
&& currentHeader != &AS_FOREACH
&& currentHeader != &AS_QFOREACH
&& currentHeader != &AS_QFOREVER
&& currentHeader != &AS_FOREVER)
&& currentHeader != &AS_ELSE
&& currentHeader != &AS_FOR
&& currentHeader != &AS_WHILE
&& currentHeader != &AS_DO
&& currentHeader != &AS_FOREACH
&& currentHeader != &AS_QFOREACH
&& currentHeader != &AS_QFOREVER
&& currentHeader != &AS_FOREVER)
return false;
if (currentHeader == &AS_WHILE && foundClosingHeader) // do-while
@@ -6619,23 +6686,105 @@ bool ASFormatter::addBracesToStatement()
if (currentChar == ';')
return false;
// do not add if a header follows
if (isCharPotentialHeader(currentLine, charNum))
if (findHeader(headers) != nullptr)
bool isLastElseBranch = shouldAddBraces == 2 && (previousHeader == &AS_IF && currentHeader == &AS_ELSE);
// old behavior
if (shouldAddBraces==1 || isLastElseBranch) {
// do not add if a header follows
if (isCharPotentialHeader(currentLine, charNum))
if (findHeader(headers) != nullptr)
return false;
// find the next semi-colon
size_t nextSemiColon = charNum;
if (currentChar != ';')
nextSemiColon = findNextChar(currentLine, ';', charNum + 1);
if (nextSemiColon == std::string::npos)
return false;
// find the next semi-colon
size_t nextSemiColon = charNum;
if (currentChar != ';')
nextSemiColon = findNextChar(currentLine, ';', charNum + 1);
if (nextSemiColon == std::string::npos)
return false;
// add closing brace before changing the line length
if (nextSemiColon == currentLine.length() - 1)
currentLine.append(" }");
else
currentLine.insert(nextSemiColon + 1, " }");
} else { // nested single line statements
if (isInExplicitBlock > 1 && !closingBracesCount) {
return false;
}
// find the next semi-colon
size_t nextSemiColon = charNum;
if (currentChar != ';')
nextSemiColon = findNextChar(currentLine, ';', charNum + 1);
bool currentIsForHeader = false;
if (nextSemiColon != std::string::npos) {
if (isCharPotentialHeader(currentLine, (int) currentLine.find_first_not_of(" \t") )) {
if (findHeader(headers) == &AS_FOR) {
currentIsForHeader = true;
--closingBracesCount;
}
}
// add closing brace before changing the line length
++closingBracesCount;
if (!currentIsForHeader)
while (closingBracesCount--) {
if (nextSemiColon == currentLine.length() - 1)
currentLine.append(" }");
else
currentLine.insert(nextSemiColon + 1, " }");
}
}
++closingBracesCount;
nextSemiColon = currentLine.find('{');
if (nextSemiColon != std::string::npos){
--closingBracesCount;
return false;
} else {
ASPeekStream stream(sourceIterator);
// loop until { or other symbol is found
while (stream.hasMoreLines()) {
std::string nextLine = ASBeautifier::trim(stream.peekNextLine());
if (nextLine.empty())
continue;
if (nextLine[0] == '{' || nextLine[nextLine.size()-1] == '{') {
--closingBracesCount;
return false;
}
if (isCharPotentialHeader(nextLine, 0) && ASBase::findHeader(nextLine, 0, headers) != nullptr ) {
break;
}
// this breaks normal if else blocks
if (nextLine[nextLine.size()-1] != ';' && nextLine[nextLine.size()-1] != '}') {
isInMultlineStatement = true;
continue;
}
if (isInMultlineStatement) {
--closingBracesCount;
return false;
}
break;
}
}
}
// add closing brace before changing the line length
if (nextSemiColon == currentLine.length() - 1)
currentLine.append(" }");
else
currentLine.insert(nextSemiColon + 1, " }");
// add opening brace
currentLine.insert(charNum, "{ ");
assert(computeChecksumIn("{}"));
@@ -6745,7 +6894,7 @@ bool ASFormatter::removeBracesFromStatement()
* @param searchStart the start position on the line (default is 0).
* @return the position on the line or std::string::npos if not found.
*/
size_t ASFormatter::findNextChar(const std::string& line, char searchChar, int searchStart /*0*/) const
size_t ASFormatter::findNextChar(std::string_view line, char searchChar, int searchStart /*0*/) const
{
// find the next searchChar
size_t i;
@@ -7160,7 +7309,7 @@ bool ASFormatter::isStructAccessModified(const std::string& firstLine, size_t in
|| findKeyword(nextLine_, i, AS_PRIVATE)
|| findKeyword(nextLine_, i, AS_PROTECTED))
return true;
std::string name = getCurrentWord(nextLine_, i);
std::string_view name = getCurrentWord(nextLine_, i);
i += name.length() - 1;
}
} // end of for loop
@@ -7330,7 +7479,7 @@ EndOfWhileLoop:
return isInIndentableBlock;
}
bool ASFormatter::isNDefPreprocStatement(const std::string& nextLine_, const std::string& preproc) const
bool ASFormatter::isNDefPreprocStatement(std::string_view nextLine_, std::string_view preproc) const
{
if (preproc == "ifndef")
return true;
@@ -7354,14 +7503,14 @@ bool ASFormatter::isNDefPreprocStatement(const std::string& nextLine_, const std
* @param index the current line index.
* @return true if the statement is EXEC SQL.
*/
bool ASFormatter::isExecSQL(const std::string& line, size_t index) const
bool ASFormatter::isExecSQL(std::string_view line, size_t index) const
{
if (line[index] != 'e' && line[index] != 'E') // quick check to reject most
return false;
std::string word;
std::string_view word;
if (isCharPotentialHeader(line, index))
word = getCurrentWord(line, index);
for (char& character : word)
for (char character : word)
character = (char) toupper(character);
if (word != "EXEC")
return false;
@@ -7369,12 +7518,14 @@ bool ASFormatter::isExecSQL(const std::string& line, size_t index) const
index2 = line.find_first_not_of(" \t", index2);
if (index2 == std::string::npos)
return false;
word.erase();
std::string_view word2;
if (isCharPotentialHeader(line, index2))
word = getCurrentWord(line, index2);
for (char& character : word)
word2 = getCurrentWord(line, index2);
for (char character : word2)
character = (char) toupper(character);
if (word != "SQL")
if (word2 != "SQL")
return false;
return true;
}
@@ -7619,7 +7770,7 @@ void ASFormatter::checkIfTemplateOpener()
templateDepth = 0;
return;
}
std::string name = getCurrentWord(nextLine_, i);
std::string_view name = getCurrentWord(nextLine_, i);
i += name.length() - 1;
} // end for loop
} // end while loop
@@ -7729,7 +7880,7 @@ void ASFormatter::updateFormattedLineSplitPoints(char appendedChar)
}
}
void ASFormatter::updateFormattedLineSplitPointsOperator(const std::string& sequence)
void ASFormatter::updateFormattedLineSplitPointsOperator(std::string_view sequence)
{
assert(maxCodeLength != std::string::npos);
assert(formattedLine.length() > 0);
@@ -8051,9 +8202,9 @@ bool ASFormatter::pointerSymbolFollows() const
* Compute the input checksum.
* This is called as an assert so it for is debug config only
*/
bool ASFormatter::computeChecksumIn(const std::string& currentLine_)
bool ASFormatter::computeChecksumIn(std::string_view currentLine_)
{
for (const char& character : currentLine_)
for (const char character : currentLine_)
if (!isWhiteSpace(character))
checksumIn += character;
return true;
@@ -8083,9 +8234,9 @@ size_t ASFormatter::getChecksumIn() const
* Compute the output checksum.
* This is called as an assert so it is for debug config only
*/
bool ASFormatter::computeChecksumOut(const std::string& beautifiedLine)
bool ASFormatter::computeChecksumOut(std::string_view beautifiedLine)
{
for (const char& character : beautifiedLine)
for (const char character : beautifiedLine)
if (!isWhiteSpace(character))
checksumOut += character;
return true;
+7 -7
View File
@@ -631,7 +631,7 @@ void ASResource::buildPreDefinitionHeaders(std::vector<const std::string*>* preD
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// check if a specific line position contains a header.
const std::string* ASBase::findHeader(const std::string& line, int i,
const std::string* ASBase::findHeader(std::string_view line, int i,
const std::vector<const std::string*>* possibleHeaders) const
{
assert(isCharPotentialHeader(line, i));
@@ -671,7 +671,7 @@ const std::string* ASBase::findHeader(const std::string& line, int i,
}
// check if a specific line position contains a keyword.
bool ASBase::findKeyword(const std::string& line, int i, const std::string& keyword) const
bool ASBase::findKeyword(std::string_view line, int i, std::string_view keyword) const
{
assert(isCharPotentialHeader(line, i));
// check the word
@@ -700,7 +700,7 @@ bool ASBase::findKeyword(const std::string& line, int i, const std::string& keyw
}
// check if a specific line position contains an operator.
const std::string* ASBase::findOperator(const std::string& line, int i,
const std::string* ASBase::findOperator(std::string_view line, int i,
const std::vector<const std::string*>* possibleOperators) const
{
assert(isCharPotentialOperator(line[i]));
@@ -721,7 +721,7 @@ const std::string* ASBase::findOperator(const std::string& line, int i,
// get the current word on a line
// index must point to the beginning of the word
std::string ASBase::getCurrentWord(const std::string& line, size_t index) const
std::string_view ASBase::getCurrentWord(std::string_view line, size_t index) const
{
//assert(isCharPotentialHeader(line, index));
size_t lineLength = line.length();
@@ -751,7 +751,7 @@ bool ASBase::isLegalNameChar(char ch) const
}
// check if a specific character can be part of a header
bool ASBase::isCharPotentialHeader(const std::string& line, size_t i) const
bool ASBase::isCharPotentialHeader(std::string_view line, size_t i) const
{
assert(!isWhiteSpace(line[i]));
char prevCh = ' ';
@@ -787,7 +787,7 @@ bool ASBase::isDigit(char ch) const
}
// check if a specific character is a digit separator
bool ASBase::isDigitSeparator(const std::string& line, int i) const
bool ASBase::isDigitSeparator(std::string_view line, int i) const
{
assert(line[i] == '\'');
// casting to (unsigned char) eliminates negative characters
@@ -800,7 +800,7 @@ bool ASBase::isDigitSeparator(const std::string& line, int i) const
}
// peek at the next unread character.
char ASBase::peekNextChar(const std::string& line, int i) const
char ASBase::peekNextChar(std::string_view line, int i) const
{
char ch = ' ';
size_t peekNum = line.find_first_not_of(" \t", i + 1);
+88 -62
View File
@@ -21,6 +21,7 @@
#include <iostream> // for cout
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#ifdef __GNUC__
@@ -52,7 +53,7 @@
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#endif
#define ASTYLE_VERSION "3.4.9"
#define ASTYLE_VERSION "3.5"
//-----------------------------------------------------------------------------
// astyle namespace
@@ -64,7 +65,7 @@ namespace astyle {
// definitions
//----------------------------------------------------------------------------
enum FileType { C_TYPE = 0, JAVA_TYPE = 1, SHARP_TYPE = 2, JS_TYPE = 3, OBJC_TYPE = 4, INVALID_TYPE = -1 };
enum FileType { C_TYPE = 0, JAVA_TYPE = 1, SHARP_TYPE = 2, JS_TYPE = 3, OBJC_TYPE = 4, GHC_TYPE = 5, INVALID_TYPE = -1 };
/* The enums below are not recognized by 'vectors' in Microsoft Visual C++
V5 when they are part of a namespace!!! Use Visual C++ V6 or higher.
@@ -175,6 +176,13 @@ enum LineEndFormat
LINEEND_CR = LINEEND_MACOLD
};
enum NegationPaddingMode
{
NEGATION_PAD_NO_CHANGE,
NEGATION_PAD_AFTER,
NEGATION_PAD_BEFORE
};
//-----------------------------------------------------------------------------
// Class ASSourceIterator
// A pure virtual class is used by ASFormatter and ASBeautifier instead of
@@ -305,28 +313,28 @@ protected:
protected: // inline functions
void init(int fileTypeArg) { baseFileType = fileTypeArg; }
bool isCStyle() const { return baseFileType == C_TYPE || baseFileType == OBJC_TYPE; }
bool isCStyle() const { return baseFileType == C_TYPE || baseFileType == OBJC_TYPE || baseFileType == GHC_TYPE; }
bool isJavaStyle() const { return baseFileType == JAVA_TYPE; }
bool isSharpStyle() const { return baseFileType == SHARP_TYPE; }
bool isJSStyle() const { return baseFileType == JS_TYPE; }
bool isObjCStyle() const { return baseFileType == OBJC_TYPE; }
bool isGHCStyle() const { return baseFileType == GHC_TYPE; }
bool isWhiteSpace(char ch) const { return (ch == ' ' || ch == '\t'); }
protected: // functions definitions are at the end of ASResource.cpp
const std::string* findHeader(const std::string& line, int i,
const std::string* findHeader(std::string_view line, int i,
const std::vector<const std::string*>* possibleHeaders) const;
bool findKeyword(const std::string& line, int i, const std::string& keyword) const;
const std::string* findOperator(const std::string& line, int i,
bool findKeyword(std::string_view line, int i, std::string_view keyword) const;
const std::string* findOperator(std::string_view line, int i,
const std::vector<const std::string*>* possibleOperators) const;
std::string getCurrentWord(const std::string& line, size_t index) const;
std::string_view getCurrentWord(std::string_view, size_t index) const;
bool isDigit(char ch) const;
bool isLegalNameChar(char ch) const;
bool isCharPotentialHeader(const std::string& line, size_t i) const;
bool isCharPotentialHeader(std::string_view line, size_t i) const;
bool isCharPotentialOperator(char ch) const;
bool isDigitSeparator(const std::string& line, int i) const;
char peekNextChar(const std::string& line, int i) const;
bool isDigitSeparator(std::string_view line, int i) const;
char peekNextChar(std::string_view line, int i) const;
}; // Class ASBase
//-----------------------------------------------------------------------------
@@ -357,6 +365,8 @@ public:
void setJSStyle();
void setObjCStyle();
void setSharpStyle();
void setGHCStyle();
void setLabelIndent(bool state);
void setMaxContinuationIndentLength(int max);
@@ -395,14 +405,14 @@ public:
protected:
void deleteBeautifierVectors();
int getNextProgramCharDistance(const std::string& line, int i) const;
int getNextProgramCharDistance(std::string_view line, int i) const;
int indexOf(const std::vector<const std::string*>& container, const std::string* element) const;
void setBlockIndent(bool state);
void setBraceIndent(bool state);
void setBraceIndentVtk(bool state);
std::string extractPreprocessorStatement(const std::string& line) const;
std::string trim(const std::string& str) const;
std::string rtrim(const std::string& str) const;
std::string extractPreprocessorStatement(std::string_view line) const;
std::string trim(std::string_view str) const;
std::string rtrim(std::string_view str) const;
// variables set by ASFormatter - must be updated in activeBeautifierStack
int inLineNumber;
@@ -423,16 +433,16 @@ protected:
private: // functions
void adjustObjCMethodDefinitionIndentation(const std::string& line_);
void adjustObjCMethodCallIndentation(const std::string& line_);
void adjustObjCMethodDefinitionIndentation(std::string_view line_);
void adjustObjCMethodCallIndentation(std::string_view line_);
void adjustParsedLineIndentation(size_t iPrelim, bool isInExtraHeaderIndent);
void computePreliminaryIndentation();
void parseCurrentLine(const std::string& line);
void computePreliminaryIndentation(std::string_view line);
void parseCurrentLine(std::string_view line);
void popLastContinuationIndent();
void processPreprocessor(const std::string& preproc, const std::string& line);
void registerContinuationIndent(const std::string& line, int i, int spaceIndentCount_,
void processPreprocessor(std::string_view preproc, std::string_view line);
void registerContinuationIndent(std::string_view line, int i, int spaceIndentCount_,
int tabIncrementIn, int minIndent, bool updateParenStack);
void registerContinuationIndentColon(const std::string& line, int i, int tabIncrementIn);
void registerContinuationIndentColon(std::string_view line, int i, int tabIncrementIn);
void initVectors();
void initTempStacksContainer(std::vector<std::vector<const std::string*>*>*& container,
std::vector<std::vector<const std::string*>*>* value);
@@ -440,20 +450,20 @@ private: // functions
void deleteBeautifierContainer(std::vector<ASBeautifier*>*& container);
void deleteTempStacksContainer(std::vector<std::vector<const std::string*>*>*& container);
int adjustIndentCountForBreakElseIfComments() const;
int computeObjCColonAlignment(const std::string& line, int colonAlignPosition) const;
int computeObjCColonAlignment(std::string_view line, int colonAlignPosition) const;
int convertTabToSpaces(int i, int tabIncrementIn) const;
int findObjCColonAlignment(const std::string& line) const;
int getContinuationIndentAssign(const std::string& line, size_t currPos) const;
int getContinuationIndentComma(const std::string& line, size_t currPos) const;
int getObjCFollowingKeyword(const std::string& line, int bracePos) const;
bool isIndentedPreprocessor(const std::string& line, size_t currPos) const;
bool isLineEndComment(const std::string& line, int startPos) const;
bool isPreprocessorConditionalCplusplus(const std::string& line) const;
bool isInPreprocessorUnterminatedComment(const std::string& line);
int findObjCColonAlignment(std::string_view line) const;
int getContinuationIndentAssign(std::string_view line, size_t currPos) const;
int getContinuationIndentComma(std::string_view line, size_t currPos) const;
int getObjCFollowingKeyword(std::string_view line, int bracePos) const;
bool isIndentedPreprocessor(std::string_view line, size_t currPos) const;
bool isLineEndComment(std::string_view line, int startPos) const;
bool isPreprocessorConditionalCplusplus(std::string_view line) const;
bool isInPreprocessorUnterminatedComment(std::string_view line);
bool isTopLevel() const;
bool statementEndsWithComma(const std::string& line, int index) const;
const std::string& getIndentedLineReturn(const std::string& newLine, const std::string& originalLine) const;
std::string getIndentedSpaceEquivalent(const std::string& line_) const;
bool statementEndsWithComma(std::string_view line, int index) const;
std::string getIndentedSpaceEquivalent(std::string_view line_) const;
std::string preLineWS(int lineIndentCount, int lineSpaceIndentCount) const;
template<typename T> void deleteContainer(T& container);
template<typename T> void initContainer(T& container, T value);
@@ -561,6 +571,11 @@ private: // variables
bool shouldIndentPreprocConditional;
bool squeezeWhitespace;
bool attemptLambdaIndentation;
bool isInAssignment;
bool isInInitializerList;
bool isInMultiLineString;
int indentCount;
int spaceIndentCount;
int spaceIndentObjCMethodAlignment;
@@ -595,6 +610,8 @@ private: // variables
// Class ASEnhancer
//-----------------------------------------------------------------------------
// TODO rewrite methods to return altered stings
class ASEnhancer : protected ASBase
{
public: // functions
@@ -606,11 +623,11 @@ public: // functions
private: // functions
void convertForceTabIndentToSpaces(std::string& line) const;
void convertSpaceIndentToForceTab(std::string& line) const;
size_t findCaseColon(const std::string& line, size_t caseIndex) const;
size_t findCaseColon(std::string_view line, size_t caseIndex) const;
int indentLine(std::string& line, int indent) const;
bool isBeginDeclareSectionSQL(const std::string& line, size_t index) const;
bool isEndDeclareSectionSQL(const std::string& line, size_t index) const;
bool isOneLineBlockReached(const std::string& line, int startChar) const;
bool isBeginDeclareSectionSQL(std::string_view line, size_t index) const;
bool isEndDeclareSectionSQL(std::string_view line, size_t index) const;
bool isOneLineBlockReached(std::string_view line, int startChar) const;
void parseCurrentLine(std::string& line, bool isInPreprocessor, bool isInSQL);
size_t processSwitchBlock(std::string& line, size_t index);
int unindentLine(std::string& line, int unindent) const;
@@ -685,7 +702,7 @@ public: // functions
LineEndFormat getLineEndFormat() const;
bool getIsLineReady() const;
void setFormattingStyle(FormatStyle style);
void setAddBracesMode(bool state);
void setAddBracesMode(int state);
void setAddOneLineBracesMode(bool state);
void setRemoveBracesMode(bool state);
void setAttachClass(bool state);
@@ -720,6 +737,8 @@ public: // functions
void setMaxCodeLength(int max);
void setObjCColonPaddingMode(ObjCColonPad mode);
void setOperatorPaddingMode(bool state);
void setNegationPaddingMode(NegationPaddingMode mode);
void setParensOutsidePaddingMode(bool state);
void setParensFirstPaddingMode(bool state);
@@ -757,8 +776,8 @@ private: // functions
char peekNextChar() const;
BraceType getBraceType();
bool adjustChecksumIn(int adjustment);
bool computeChecksumIn(const std::string& currentLine_);
bool computeChecksumOut(const std::string& beautifiedLine);
bool computeChecksumIn(std::string_view currentLine_);
bool computeChecksumOut(std::string_view beautifiedLine);
bool addBracesToStatement();
bool removeBracesFromStatement();
bool commentAndHeaderFollows();
@@ -774,22 +793,22 @@ private: // functions
bool isClosingHeader(const std::string* header) const;
bool isCurrentBraceBroken() const;
bool isDereferenceOrAddressOf() const;
bool isExecSQL(const std::string& line, size_t index) const;
bool isEmptyLine(const std::string& line) const;
bool isExecSQL(std::string_view line, size_t index) const;
bool isEmptyLine(std::string_view line) const;
bool isExternC() const;
bool isMultiStatementLine() const;
bool isNextWordSharpNonParenHeader(int startChar) const;
bool isNonInStatementArrayBrace() const;
bool isNumericVariable(const std::string& word) const;
bool isNumericVariable(std::string_view word) const;
bool isOkToSplitFormattedLine();
bool isPointerOrReference() const;
bool isPointerOrReferenceCentered() const;
bool isPointerOrReferenceVariable(const std::string& word) const;
bool isPointerToPointer(const std::string& line, int currPos) const;
bool isPointerOrReferenceVariable(std::string_view word) const;
bool isPointerToPointer(std::string_view line, int currPos) const;
bool isSharpStyleWithParen(const std::string* header) const;
bool isStructAccessModified(const std::string& firstLine, size_t index) const;
bool isIndentablePreprocessorBlock(const std::string& firstLine, size_t index);
bool isNDefPreprocStatement(const std::string& nextLine_, const std::string& preproc) const;
bool isNDefPreprocStatement(std::string_view nextLine_, std::string_view preproc) const;
bool isUnaryOperator() const;
bool isUniformInitializerBrace() const;
bool isImmediatelyPostCast() const;
@@ -802,19 +821,19 @@ private: // functions
int findObjCColonAlignment() const;
int getCurrentLineCommentAdjustment();
int getNextLineCommentAdjustment();
int isOneLineBlockReached(const std::string& line, int startChar) const;
int isOneLineBlockReached(std::string_view line, int startChar) const;
void adjustComments();
void appendChar(char ch, bool canBreakLine);
void appendCharInsideComments();
void appendClosingHeader();
void appendOperator(const std::string& sequence, bool canBreakLine = true);
void appendSequence(const std::string& sequence, bool canBreakLine = true);
void appendOperator(std::string_view sequence, bool canBreakLine = true);
void appendSequence(std::string_view sequence, bool canBreakLine = true);
void appendSpacePad();
void appendSpaceAfter();
void breakLine(bool isSplitLine = false);
void buildLanguageVectors();
void updateFormattedLineSplitPoints(char appendedChar);
void updateFormattedLineSplitPointsOperator(const std::string& sequence);
void updateFormattedLineSplitPointsOperator(std::string_view sequence);
void checkIfTemplateOpener();
void clearFormattedLineSplitPoints();
void convertTabToSpaces();
@@ -856,11 +875,11 @@ private: // functions
void trimContinuationLine();
void updateFormattedLineSplitPointsPointerOrReference(size_t index);
size_t findFormattedLineSplitPoint() const;
size_t findNextChar(const std::string& line, char searchChar, int searchStart = 0) const;
const std::string* checkForHeaderFollowingComment(const std::string& firstLine) const;
size_t findNextChar(std::string_view line, char searchChar, int searchStart = 0) const;
const std::string* checkForHeaderFollowingComment(std::string_view firstLine) const;
const std::string* getFollowingOperator() const;
std::string getPreviousWord(const std::string& line, int currPos) const;
std::string peekNextText(const std::string& firstLine,
std::string getPreviousWord(const std::string& line, int currPos, bool allowDots = false) const;
std::string peekNextText(std::string_view firstLine,
bool endOnEmptyLine = false,
const std::shared_ptr<ASPeekStream>& streamArg = nullptr) const;
@@ -889,6 +908,7 @@ private: // variables
std::string readyFormattedLine;
std::string verbatimDelimiter;
const std::string* currentHeader;
const std::string* previousHeader;
char currentChar;
char previousChar;
char previousNonWSChar;
@@ -905,8 +925,9 @@ private: // variables
int templateDepth;
int squareBracketCount;
int parenthesesCount;
int squeezeEmptyLineNum;
int squeezeEmptyLineCount;
int closingBracesCount;
size_t squeezeEmptyLineNum;
size_t squeezeEmptyLineCount;
size_t checksumIn;
size_t checksumOut;
@@ -939,13 +960,14 @@ private: // variables
ReferenceAlign referenceAlignment;
ObjCColonPad objCColonPadMode;
LineEndFormat lineEnd;
NegationPaddingMode negationPadMode;
bool isVirgin;
bool isInVirginLine;
bool shouldPadCommas;
bool shouldPadOperators;
bool shouldPadParensOutside;
bool shouldPadFirstParen;
bool shouldPadEmptyParens;
bool shouldPadParensInside;
bool shouldPadHeader;
@@ -1039,7 +1061,7 @@ private: // variables
bool shouldBreakClosingHeaderBraces;
bool shouldBreakElseIfs;
bool shouldBreakLineAfterLogical;
bool shouldAddBraces;
int shouldAddBraces;
bool shouldAddOneLineBraces;
bool shouldRemoveBraces;
bool shouldPadMethodColon;
@@ -1092,15 +1114,19 @@ private: // variables
bool processedFirstConditional;
bool isJavaStaticConstructor;
bool isInAllocator;
bool isInMultlineStatement;
int isInExplicitBlock;
private: // inline functions
// append the CURRENT character (curentChar) to the current formatted line.
// append the CURRENT character (currentChar) to the current formatted line.
void appendCurrentChar(bool canBreakLine = true)
{ appendChar(currentChar, canBreakLine); }
// check if a specific sequence exists in the current placement of the current line
bool isSequenceReached(const char* sequence) const
{ return currentLine.compare(charNum, strlen(sequence), sequence) == 0; }
bool isSequenceReached(std::string_view sequence) const
{
return currentLine.compare(charNum, sequence.length(), sequence) == 0;
}
// call ASBase::findHeader for the current character
const std::string* findHeader(const std::vector<const std::string*>* headers_)
+60 -8
View File
@@ -34,6 +34,7 @@
//-----------------------------------------------------------------------------
#include "astyle_main.h"
#include "astyle.h"
#include <algorithm>
#include <cerrno>
@@ -1340,6 +1341,7 @@ void ASConsole::getFileNames(const std::string& directory, const std::vector<std
{
// get file status
std::string entryFilepath = directory + g_fileSeparator + entry->d_name;
if (stat(entryFilepath.c_str(), &statbuf) != 0)
{
if (errno == EOVERFLOW) // file over 2 GB is OK
@@ -1701,8 +1703,10 @@ void ASConsole::getFilePaths(const std::string& filePath)
}
else
{
// verify a single file is not a directory (needed on Linux)
std::string entryFilepath = targetDirectory + g_fileSeparator + targetFilename;
struct stat statbuf;
if (stat(entryFilepath.c_str(), &statbuf) == 0 && (statbuf.st_mode & S_IFREG))
fileName.emplace_back(entryFilepath);
@@ -2087,6 +2091,12 @@ void ASConsole::printHelp() const
std::cout << " --pad-comma OR -xg\n";
std::cout << " Insert space padding after commas.\n";
std::cout << std::endl;
std::cout << " --pad-negation\n";
std::cout << " Insert space padding after negations.\n";
std::cout << std::endl;
std::cout << " --pad-negation=before\n";
std::cout << " Insert space padding also before negations.\n";
std::cout << std::endl;
std::cout << " --pad-paren OR -P\n";
std::cout << " Insert space padding around parenthesis on both the outside\n";
std::cout << " and the inside.\n";
@@ -2115,10 +2125,16 @@ void ASConsole::printHelp() const
std::cout << " --pad-brackets\n";
std::cout << " Insert space padding around square brackets on both the outside\n";
std::cout << " and the inside (experimental).\n";
std::cout << " and the inside.\n";
std::cout << std::endl;
std::cout << " --pad-brackets-in\n";
std::cout << " Insert space padding around square brackets on the inside only.\n";
std::cout << std::endl;
std::cout << " --pad-brackets-out\n";
std::cout << " Insert space padding around square brackets on the outside only.\n";
std::cout << std::endl;
std::cout << " --unpad-brackets\n";
std::cout << " Remove unnecessary space padding around square brackets (experimental).\n";
std::cout << " Remove unnecessary space padding around square brackets.\n";
std::cout << std::endl;
std::cout << " --delete-empty-lines OR -xe\n";
@@ -2130,10 +2146,10 @@ void ASConsole::printHelp() const
std::cout << " previous lines.\n";
std::cout << std::endl;
std::cout << " --squeeze-lines=#\n";
std::cout << " Remove superfluous empty lines exceeding the given number (experimental).\n";
std::cout << " Remove superfluous empty lines exceeding the given number.\n";
std::cout << std::endl;
std::cout << " --squeeze-ws\n";
std::cout << " Remove superfluous whitespace (experimental).\n";
std::cout << " Remove superfluous whitespace.\n";
std::cout << std::endl;
std::cout << " --align-pointer=type OR -k1\n";
std::cout << " --align-pointer=middle OR -k2\n";
@@ -2165,6 +2181,7 @@ void ASConsole::printHelp() const
std::cout << " statement residing on the same line.\n";
std::cout << std::endl;
std::cout << " --add-braces OR -j\n";
std::cout << " --add-braces=nested (experimental)\n";
std::cout << " Add braces to unbraced one line conditional statements.\n";
std::cout << std::endl;
std::cout << " --add-one-line-braces OR -J\n";
@@ -2225,6 +2242,9 @@ void ASConsole::printHelp() const
std::cout << " --mode=js\n";
std::cout << " Indent a JavaScript source file (experimental).\n";
std::cout << std::endl;
std::cout << " --mode=ghc\n";
std::cout << " Indent a GHC source file (experimental).\n";
std::cout << std::endl;
std::cout << "Objective-C Options:\n";
std::cout << "--------------------\n";
std::cout << " --pad-method-prefix OR -xQ\n";
@@ -2368,8 +2388,11 @@ void ASConsole::processFiles()
getFilePaths(fileNameVectorName);
// loop thru fileName vector formatting the files
for (const std::string& file : fileName)
formatFile(file);
for (const std::string& file : fileName) {
if (!stringEndsWith(file, origSuffix))
formatFile(file);
}
}
// files are processed, display stats
@@ -2791,7 +2814,7 @@ void ASConsole::sleep(int seconds) const
while (clock() < endwait) {}
}
bool ASConsole::stringEndsWith(const std::string& str, const std::string& suffix) const
bool ASConsole::stringEndsWith(std::string_view str, std::string_view suffix) const
{
int strIndex = (int) str.length() - 1;
int suffixIndex = (int) suffix.length() - 1;
@@ -3139,6 +3162,7 @@ bool ASOptions::parseOptions(std::vector<std::string>& optionsVector, const std:
void ASOptions::parseOption(const std::string& arg, const std::string& errorInfo)
{
NegationPaddingMode negationPaddingMode = NEGATION_PAD_NO_CHANGE;
if (isOption(arg, "A1", "style=allman") || isOption(arg, "style=bsd") || isOption(arg, "style=break"))
{
formatter.setFormattingStyle(STYLE_ALLMAN);
@@ -3229,6 +3253,11 @@ void ASOptions::parseOption(const std::string& arg, const std::string& errorInfo
formatter.setObjCStyle();
formatter.setModeManuallySet(true);
}
else if (isOption(arg, "mode=ghc"))
{
formatter.setGHCStyle();
formatter.setModeManuallySet(true);
}
else if (isParamOption(arg, "t", "indent=tab="))
{
int spaceNum = 4;
@@ -3417,6 +3446,14 @@ void ASOptions::parseOption(const std::string& arg, const std::string& errorInfo
{
formatter.setOperatorPaddingMode(true);
}
else if (isOption(arg, "pad-negation"))
{
negationPaddingMode = NEGATION_PAD_AFTER;
}
else if (isOption(arg, "pad-negation=before"))
{
negationPaddingMode = NEGATION_PAD_BEFORE;
}
else if (isOption(arg, "xg", "pad-comma"))
{
formatter.setCommaPaddingMode(true);
@@ -3465,9 +3502,13 @@ void ASOptions::parseOption(const std::string& arg, const std::string& errorInfo
{
formatter.setBreakOneLineHeadersMode(true);
}
else if (isOption(arg, "add-braces=nested"))
{
formatter.setAddBracesMode(2);
}
else if (isOption(arg, "j", "add-braces"))
{
formatter.setAddBracesMode(true);
formatter.setAddBracesMode(1);
}
else if (isOption(arg, "J", "add-one-line-braces"))
{
@@ -3614,6 +3655,9 @@ void ASOptions::parseOption(const std::string& arg, const std::string& errorInfo
{
isOptionError(arg, errorInfo);
}
formatter.setNegationPaddingMode(negationPaddingMode);
} // End of parseOption function
// Continuation of parseOption.
@@ -3767,6 +3811,14 @@ bool ASOptions::parseOptionContinued(const std::string& arg, const std::string&
formatter.setBracketsOutsidePaddingMode(true);
formatter.setBracketsInsidePaddingMode(true);
}
else if (isOption(arg, "pad-brackets-in"))
{
formatter.setBracketsInsidePaddingMode(true);
}
else if (isOption(arg, "pad-brackets-out"))
{
formatter.setBracketsOutsidePaddingMode(true);
}
else if (isOption(arg, "unpad-brackets"))
{
formatter.setBracketsUnPaddingMode(true);
+1 -1
View File
@@ -309,7 +309,7 @@ public: // functions
void setStdPathIn(const std::string& path);
void setStdPathOut(const std::string& path);
void standardizePath(std::string& path, bool removeBeginningSeparator = false) const;
bool stringEndsWith(const std::string& str, const std::string& suffix) const;
bool stringEndsWith(std::string_view str, std::string_view suffix) const;
void updateExcludeVector(const std::string& suffixParam);
std::vector<std::string> getExcludeVector() const;
std::vector<bool> getExcludeHitsVector() const;
+1 -1
View File
@@ -20,7 +20,7 @@ do
fi
# call the latest astyle here
../../AStyle/build_local/astyle "$arg" < tmp.cpp > "$dir/tmp.cpp.new"
../../AStyle/build_local/astyle --squeeze-lines=1 "$arg" < tmp.cpp > "$dir/tmp.cpp.new"
diff $dir/tmp.cpp.old $dir/tmp.cpp.new
if [ $? -eq 0 ]; then
rm "$dir/tmp.cpp.new"