Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3524d66639 | ||
|
|
3f3f90b577 | ||
|
|
af17f3b833 | ||
|
|
88a2903caf | ||
|
|
4154588caf | ||
|
|
9369c8455f | ||
|
|
aa7e2febec | ||
|
|
4e72cf7e15 | ||
|
|
683a618343 | ||
|
|
422985f01b | ||
|
|
9fd80e1abe | ||
|
|
485382e2aa | ||
|
|
b27cccdb9d | ||
|
|
8c69e067ec | ||
|
|
b09b2355e0 | ||
|
|
86532b948f | ||
|
|
3623229876 | ||
|
|
bac6279b26 | ||
|
|
050c108c28 | ||
|
|
bcf5bb4a5e | ||
|
|
9a77b83a8b | ||
|
|
fd449b0e5e | ||
|
|
803ba0955a | ||
|
|
086ed3a3d3 | ||
|
|
9af46ccc6c | ||
|
|
04aabdd005 | ||
|
|
15cf1e018b | ||
|
|
f32c555bc1 | ||
|
|
7e97becbcf | ||
|
|
21b58e214e | ||
|
|
16c4a56aa4 | ||
|
|
aa58fe1aa4 | ||
|
|
87e0136e5f | ||
|
|
3bdf5fb041 | ||
|
|
b66f3cb173 | ||
|
|
055c06d4c5 | ||
|
|
93605a0147 |
@@ -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,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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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})
|
||||
|
||||
|
||||
+60
-19
@@ -60,7 +60,7 @@
|
||||
|
||||
<button onclick="topFunction()" id="topBtn" title="Go to Contents"><b>Top</b></button>
|
||||
|
||||
<h1>Artistic Style 3.4.12</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 Modify 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>
|
||||
@@ -402,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 < and > 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>
|
||||
@@ -416,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 < <em>OriginalSourceFile</em> | less
|
||||
@@ -1547,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>
|
||||
|
||||
@@ -1673,6 +1675,41 @@ isBar = false;
|
||||
bar(a, b);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
</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>
|
||||
</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>
|
||||
</p>
|
||||
<p id="_pad-paren">
|
||||
@@ -1963,7 +2000,7 @@ string ^s1;</pre>
|
||||
char& foo2;
|
||||
string^ s1;</pre>
|
||||
</div>
|
||||
<div class="code">
|
||||
<div class="code" style="margin-top:1em">
|
||||
<pre>char* foo1;
|
||||
char & foo2;
|
||||
string ^s1;</pre>
|
||||
@@ -1973,7 +2010,7 @@ string ^s1;</pre>
|
||||
char & foo2;
|
||||
string ^ s1;</pre>
|
||||
</div>
|
||||
<div class="code">
|
||||
<div class="code" style="margin-top:1em">
|
||||
<pre>char* foo1;
|
||||
char & foo2;
|
||||
string ^s1;</pre>
|
||||
@@ -2001,14 +2038,14 @@ string ^s1;</pre>
|
||||
becomes (with align-reference=type):</p>
|
||||
<pre>char& foo1;</pre>
|
||||
</div>
|
||||
<div class="code">
|
||||
<div class="code" style="margin-top:1em">
|
||||
<pre>char& foo2;</pre>
|
||||
<p class="code">
|
||||
becomes (with align-reference=middle):</p>
|
||||
<pre>char & foo2;</pre>
|
||||
</div>
|
||||
<div class="code">
|
||||
<pre>char& foo3;</pre>
|
||||
<div class="code" style="margin-top:1em">
|
||||
<pre>char& foo3;</pre>
|
||||
<p class="code">
|
||||
becomes (with align-reference=name):</p>
|
||||
<pre>char &foo3;</pre>
|
||||
@@ -2173,7 +2210,7 @@ else
|
||||
<p>
|
||||
</p>
|
||||
<p id="_break-return-type">
|
||||
<code class="title">--break-return-type / -xB</code><br />
|
||||
<code class="title">--break-return-type / -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
|
||||
@@ -2188,7 +2225,7 @@ Foo(bool isFoo);</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p id="_attach-return-type">
|
||||
<code class="title">--attach-return-type / -xf</code><br />
|
||||
<code class="title">--attach-return-type / -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
|
||||
@@ -2315,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>
|
||||
</p>
|
||||
<hr />
|
||||
@@ -2467,7 +2508,7 @@ Foo(bool isFoo);</pre>
|
||||
</p>
|
||||
<p id="_pad-method-colon">
|
||||
<code class="title">--pad-method-colon=none / -xP0<br />
|
||||
--pad-method-colon=all / -xP1<br />
|
||||
--pad-method-colon=all / -xP1<br />
|
||||
--pad-method-colon=after / -xP2<br />
|
||||
--pad-method-colon=before / -xP3
|
||||
</code><br />
|
||||
|
||||
@@ -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
-610
File diff suppressed because it is too large
Load Diff
+82
-42
@@ -14,95 +14,135 @@
|
||||
|
||||
<h1>Artistic Style Release Notes</h1>
|
||||
|
||||
<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>added "--pad-brackets-in" and "--pad-brackets-out" options (https://gitlab.com/saalen/astyle/-/issues/33)</li>
|
||||
<li>fixed indentation of initializer lists (https://gitlab.com/saalen/astyle/-/issues/28)</li>
|
||||
<li>fixed crash with "--add-braces=nested" applied to if-else blocks (https://gitlab.com/saalen/astyle/-/issues/36)</li>
|
||||
<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>added 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>"--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>
|
||||
<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>fixed missing indent in function parameter list (https://gitlab.com/saalen/astyle/-/issues/16)</li>
|
||||
<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>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>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 empty 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 & 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 & 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 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 "struct" (#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 "struct" (#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>
|
||||
|
||||
+7
-1
@@ -1,4 +1,4 @@
|
||||
.TH astyle 1 "2024-01-19" "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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
+85
-60
@@ -72,7 +72,7 @@ ASBeautifier::ASBeautifier()
|
||||
setPreprocDefineIndent(false);
|
||||
setPreprocConditionalIndent(false);
|
||||
setAlignMethodColon(false);
|
||||
isInAssignment = isInInitializerList = false;
|
||||
isInAssignment = isInInitializerList = isInMultiLineString = false;
|
||||
|
||||
// initialize ASBeautifier member vectors
|
||||
beautifierFileType = INVALID_TYPE; // reset to an invalid type
|
||||
@@ -212,6 +212,8 @@ ASBeautifier::ASBeautifier(const ASBeautifier& other) : ASBase(other)
|
||||
attemptLambdaIndentation = other.attemptLambdaIndentation;
|
||||
isInAssignment = other.isInAssignment;
|
||||
isInInitializerList = other.isInInitializerList;
|
||||
isInMultiLineString = other.isInMultiLineString;
|
||||
|
||||
namespaceIndent = other.namespaceIndent;
|
||||
braceIndent = other.braceIndent;
|
||||
braceIndentVtk = other.braceIndentVtk;
|
||||
@@ -605,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
|
||||
@@ -649,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
|
||||
{
|
||||
@@ -664,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")
|
||||
{
|
||||
@@ -672,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")
|
||||
@@ -682,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -702,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.
|
||||
@@ -803,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;
|
||||
@@ -1312,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)
|
||||
@@ -1349,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);
|
||||
@@ -1361,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;
|
||||
}
|
||||
|
||||
@@ -1418,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);
|
||||
@@ -1460,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;
|
||||
@@ -1533,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;
|
||||
@@ -1558,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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1696,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] == '=');
|
||||
|
||||
@@ -1777,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);
|
||||
|
||||
@@ -1797,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] == '=');
|
||||
|
||||
@@ -1825,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] == ',');
|
||||
|
||||
@@ -1886,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
|
||||
@@ -1920,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;
|
||||
}
|
||||
@@ -1932,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")
|
||||
@@ -1964,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)
|
||||
{
|
||||
@@ -1999,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
|
||||
@@ -2089,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(const std::string& line)
|
||||
void ASBeautifier::computePreliminaryIndentation(std::string_view line)
|
||||
{
|
||||
indentCount = 0;
|
||||
spaceIndentCount = 0;
|
||||
@@ -2353,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");
|
||||
@@ -2366,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
|
||||
@@ -2397,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)
|
||||
@@ -2474,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++)
|
||||
@@ -2532,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)
|
||||
@@ -2546,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);
|
||||
@@ -2586,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')
|
||||
@@ -2634,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;
|
||||
@@ -2646,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;
|
||||
@@ -2661,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)
|
||||
{
|
||||
@@ -2706,10 +2723,11 @@ 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] : ' ';
|
||||
@@ -2757,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;
|
||||
@@ -3199,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
|
||||
@@ -3787,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;
|
||||
}
|
||||
@@ -3800,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;
|
||||
}
|
||||
@@ -3822,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;
|
||||
}
|
||||
@@ -3832,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;
|
||||
}
|
||||
@@ -3894,7 +3919,7 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
|
||||
// GL28: method calls have to contain only alphanumeric identifier
|
||||
size_t openParenPos = line.find(AS_OPEN_PAREN, i);
|
||||
|
||||
std::string methodName = getNextWord(line, 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)
|
||||
@@ -3910,7 +3935,7 @@ void ASBeautifier::parseCurrentLine(const std::string& line)
|
||||
}
|
||||
|
||||
// GL28: do not mixup template closing ">>" with IO operator
|
||||
std::string searchTemplatePattern = line.substr(0, i);
|
||||
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
|
||||
|
||||
+11
-12
@@ -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;
|
||||
|
||||
+127
-77
@@ -47,6 +47,7 @@ ASFormatter::ASFormatter()
|
||||
isInStruct = false;
|
||||
shouldPadCommas = false;
|
||||
shouldPadOperators = false;
|
||||
negationPadMode = NEGATION_PAD_NO_CHANGE;
|
||||
shouldPadParensOutside = false;
|
||||
shouldPadFirstParen = false;
|
||||
shouldPadEmptyParens = false;
|
||||
@@ -1424,6 +1425,7 @@ std::string ASFormatter::nextLine()
|
||||
}
|
||||
}
|
||||
|
||||
// #569
|
||||
if (shouldBreakBlocks
|
||||
&& isOkToBreakBlock(braceTypeStack->back())
|
||||
&& !isHeaderInMultiStatementLine)
|
||||
@@ -1534,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
|
||||
@@ -1752,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)
|
||||
@@ -1768,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);
|
||||
}
|
||||
|
||||
@@ -1895,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;
|
||||
@@ -2229,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:
|
||||
@@ -2818,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
|
||||
}
|
||||
@@ -3043,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();
|
||||
@@ -3059,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();
|
||||
@@ -3254,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"
|
||||
@@ -3266,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"
|
||||
@@ -3297,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))
|
||||
@@ -3325,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;
|
||||
}
|
||||
@@ -3392,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 != '('
|
||||
@@ -3421,6 +3431,7 @@ bool ASFormatter::isPointerOrReference() const
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nextChar == '*'
|
||||
|| previousNonWSChar == '='
|
||||
|| previousNonWSChar == '('
|
||||
@@ -3430,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])
|
||||
@@ -3454,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;
|
||||
}
|
||||
|
||||
@@ -3550,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)
|
||||
@@ -3576,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;
|
||||
}
|
||||
@@ -3638,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())
|
||||
@@ -3665,6 +3694,7 @@ bool ASFormatter::isPointerOrReferenceVariable(const std::string& word) const
|
||||
if (prevWord == "is")
|
||||
retval = false;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -3673,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] == '*')
|
||||
@@ -3752,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;
|
||||
}
|
||||
@@ -3800,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] == '{');
|
||||
|
||||
@@ -4052,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
|
||||
@@ -4211,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
|
||||
@@ -4258,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?)
|
||||
@@ -4396,7 +4434,7 @@ void ASFormatter::formatPointerOrReferenceToType()
|
||||
}
|
||||
|
||||
// https://sourceforge.net/p/astyle/bugs/537/
|
||||
if (previousNonWSChar == ',' && currentChar != ' ')
|
||||
if ((previousNonWSChar == ',' || previousNonWSChar == '[') && currentChar != ' ')
|
||||
appendSpacePad();
|
||||
|
||||
formattedLine.append(sequenceToInsert);
|
||||
@@ -4444,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++)
|
||||
@@ -4459,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))
|
||||
@@ -4584,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);
|
||||
@@ -5116,6 +5156,8 @@ void ASFormatter::formatOpeningBrace(BraceType braceType)
|
||||
|
||||
bool breakBrace = isCurrentBraceBroken();
|
||||
|
||||
//478
|
||||
|
||||
if (breakBrace)
|
||||
{
|
||||
if (isBeforeAnyComment() && isOkToBreakBlock(braceType) && sourceIterator->hasMoreLines())
|
||||
@@ -5313,10 +5355,13 @@ void ASFormatter::formatClosingBrace(BraceType braceType)
|
||||
}
|
||||
else {
|
||||
// GH18
|
||||
// #569
|
||||
isAppendPostBlockEmptyLineRequested = !(shouldBreakBlocks && shouldAttachClosingWhile)
|
||||
|| currentHeader != &AS_DO;
|
||||
}
|
||||
|
||||
} else {
|
||||
isAppendPostBlockEmptyLineRequested = !currentHeader && shouldBreakBlocks;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5340,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
|
||||
@@ -5788,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());
|
||||
@@ -6418,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)
|
||||
@@ -6512,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)
|
||||
@@ -6525,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++;
|
||||
@@ -6846,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;
|
||||
@@ -7261,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
|
||||
@@ -7431,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;
|
||||
@@ -7455,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;
|
||||
@@ -7470,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;
|
||||
}
|
||||
@@ -7720,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
|
||||
@@ -7830,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);
|
||||
@@ -8152,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;
|
||||
@@ -8184,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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
+70
-55
@@ -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.12"
|
||||
#define ASTYLE_VERSION "3.5"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// astyle namespace
|
||||
@@ -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
|
||||
@@ -315,19 +323,18 @@ protected: // inline functions
|
||||
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
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -398,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;
|
||||
@@ -426,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(const std::string& line);
|
||||
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);
|
||||
@@ -443,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);
|
||||
@@ -567,6 +574,7 @@ private: // variables
|
||||
|
||||
bool isInAssignment;
|
||||
bool isInInitializerList;
|
||||
bool isInMultiLineString;
|
||||
|
||||
int indentCount;
|
||||
int spaceIndentCount;
|
||||
@@ -602,6 +610,8 @@ private: // variables
|
||||
// Class ASEnhancer
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// TODO rewrite methods to return altered stings
|
||||
|
||||
class ASEnhancer : protected ASBase
|
||||
{
|
||||
public: // functions
|
||||
@@ -613,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;
|
||||
@@ -727,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);
|
||||
|
||||
@@ -764,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();
|
||||
@@ -781,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;
|
||||
@@ -809,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();
|
||||
@@ -863,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;
|
||||
|
||||
@@ -948,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;
|
||||
@@ -1110,8 +1123,10 @@ private: // inline functions
|
||||
{ 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_)
|
||||
|
||||
@@ -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";
|
||||
@@ -2378,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
|
||||
@@ -2801,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;
|
||||
@@ -3149,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);
|
||||
@@ -3432,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);
|
||||
@@ -3633,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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user