You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<divid="projectbrief">Fortran library of functions for common string manipulations</div>
28
28
</td>
@@ -83,8 +83,10 @@ <h2>Introduction</h2>
83
83
<li><b>str_zfill</b> - Pad a string with zeroes ("0") to specified width. If width is <= input string width, then the original string is returned.</li>
84
84
<li><b>str_center</b> - Center a string to a specified width. The default character to fill in the centered string is a blank character.</li>
85
85
<li><b>str_reverse</b> - Reverse a string.</li>
86
+
<li><b>str_test</b> - Return .true. is a substring is found in a string, .false. otherwise.</li>
87
+
<li><b>str_swapcase</b> - Swap the case of letters in a string.</li>
86
88
</ul>
87
-
<p>All functions return a deferred-length, allocatable character scalar (<code>character(len=:), allocatable</code>) with the exception of **<code>str_count</code>** which returns an integer.</p>
89
+
<p>All functions return a deferred-length, allocatable character scalar (<code>character(len=:), allocatable</code>) with the exception of **<code>str_count</code>** which returns an integer and **<code>str_test</code>** which returns a logical.</p>
88
90
<h2>Requirements</h2>
89
91
<ul>
90
92
<li>Fortran compiler (tested with gfortran 4.8.4 and later)</li>
@@ -94,9 +96,9 @@ <h2>Build and Installation</h2>
94
96
<divclass="fragment"><divclass="line">[FC=... FFLAGS="..." PREFIX="..."] make # Build</div><divclass="line">make test # Test</div><divclass="line">[sudo] [FC=... FFLAGS="..." PREFIX="..."] make install # Install (sudo access required if install to system area)</div></div><!-- fragment --><h2>Usage</h2>
95
97
<p>This package provides a module file (**<code><prefix>/include/strings.mod</code>**) and both a shared object library (**<code><prefix>/lib/libfstrings.so</code>**) and a static library (**<code><prefix>/lib/libfstrings.a</code>**). To use this <code>fortran-strings</code> in your Fortran program, you must use the <code>USE</code> statement in your main program or procedure source and during compile, you must specify the library of your choice to the compiler/linker.</p>
96
98
<p>Example code:</p>
97
-
<divclass="fragment"><divclass="line"><spanclass="keyword">program</span> test</div><divclass="line"><spanclass="keywordtype">use </span><aclass="code" href="namespacestrings.html">strings</a></div><divclass="line"><spanclass="keywordtype">implicit none</span></div><divclass="line"></div><divclass="line"><spanclass="keywordtype">character(len=:)</span>, <spanclass="keywordtype">allocatable</span> :: mystring</div><divclass="line"><spanclass="keywordtype">integer</span> :: icount</div><divclass="line"></div><divclass="line">mystring=<spanclass="stringliteral">"Hello World! Hello from Fortran!"</span></div><divclass="line">icount=<aclass="code" href="namespacestrings.html#a1b755da0409a70ccc4c25c1de4e7e009">str_count</a>(mystring,<spanclass="stringliteral">"Hello"</span>) <spanclass="comment">! Return a count of "Hello" in mystring</span></div><divclass="line"><spanclass="keyword">write</span>(6,*)<spanclass="stringliteral">"icount = "</span>,icount</div><divclass="line"></div><divclass="line"><spanclass="keyword">end program </span>test</div></div><!-- fragment --><p>Example compile and link to <em><b>static</b></em> library using gfortran:</p>
99
+
<divclass="fragment"><divclass="line"><spanclass="keyword">program</span> test</div><divclass="line"><spanclass="keywordtype">use </span><aclass="code" href="namespacestrings.html">strings</a></div><divclass="line"><spanclass="keywordtype">implicit none</span></div><divclass="line"></div><divclass="line"><spanclass="keywordtype">character(len=:)</span>, <spanclass="keywordtype">allocatable</span> :: mystring</div><divclass="line"><spanclass="keywordtype">integer</span> :: icount</div><divclass="line"></div><divclass="line">mystring=<spanclass="stringliteral">"Hello World! Hello from Fortran!"</span></div><divclass="line">icount=<aclass="code" href="namespacestrings.html#a4c059bd22bb1423242489b8b421f6119">str_count</a>(mystring,<spanclass="stringliteral">"Hello"</span>) <spanclass="comment">! Return a count of "Hello" in mystring</span></div><divclass="line"><spanclass="keyword">write</span>(6,*)<spanclass="stringliteral">"icount = "</span>,icount</div><divclass="line"></div><divclass="line"><spanclass="keyword">end program </span>test</div></div><!-- fragment --><p>Example compile and link to the <em><b>static</b></em> library using gfortran:</p>
98
100
<divclass="fragment"><divclass="line">gfortran -I<prefix>/include -o test.x test.f90 <prefix>/lib/libfstrings.a</div></div><!-- fragment --><p>Note that this does not make the executable 100% static.</p>
99
-
<p>Example compile and link to <em><b>shared object</b></em> library using gfortran:</p>
101
+
<p>Example compile and link to the <em><b>shared object</b></em> library using gfortran:</p>
100
102
<divclass="fragment"><divclass="line">gfortran -I<prefix>/include -o test.x test.f90 -L<prefix>/lib -lfstrings</div></div><!-- fragment --><p>Note that when compiling and linking to shared object libraries, the library path must be specified in the appropriate environment variable prior to invocation (Linux: <code>LD_LIBRARY_PATH</code>; macOS: <code>DYLD_LIBRARY_PATH</code>). </p>
<trclass="memdesc:a1b755da0409a70ccc4c25c1de4e7e009"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Count the occurrences of a substring in a string. <ahref="#a1b755da0409a70ccc4c25c1de4e7e009">More...</a><br/></td></tr>
<trclass="memdesc:a4c059bd22bb1423242489b8b421f6119"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Count the occurrences of a substring in a string. <ahref="#a4c059bd22bb1423242489b8b421f6119">More...</a><br/></td></tr>
<trclass="memdesc:a2d557ee85358067ac58c78aeda61fefc"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Replace a substring with another substring within a parent string. <ahref="#a2d557ee85358067ac58c78aeda61fefc">More...</a><br/></td></tr>
<trclass="memdesc:a71f27e53beff6353ceead343b10761ec"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Reverse a string. <ahref="#a71f27e53beff6353ceead343b10761ec">More...</a><br/></td></tr>
<trclass="memdesc:a0969d192486101d11d1bc69f68ee3d5b"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Return .true. if substr is in str, .false. otherwise. <ahref="#a0969d192486101d11d1bc69f68ee3d5b">More...</a><br/></td></tr>
<trclass="memdesc:a5c3bdabb916c605add94b0490c0a300e"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Return str with case of letters swapped. <ahref="#a5c3bdabb916c605add94b0490c0a300e">More...</a><br/></td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">str</td><td>- string to count from </td></tr>
179
191
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">substr</td><td>- substring to count </td></tr>
192
+
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">match_case</td><td>- use case sensitivity (.true.) or not (.false. [DEFAULT]) <b></b>[OPTIONAL] </td></tr>
<p>Return .true. if substr is in str, .false. otherwise. </p>
403
+
<dlclass="params"><dt>Parameters</dt><dd>
404
+
<tableclass="params">
405
+
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">str</td><td>- string to work on </td></tr>
406
+
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">substr</td><td>- string to search for in str </td></tr>
407
+
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">match_case</td><td>- use case sensitivity (.true.) or not (.false. [DEFAULT]) <b></b>[OPTIONAL] </td></tr>
408
+
</table>
409
+
</dd>
410
+
</dl>
411
+
<dlclass="section return"><dt>Returns</dt><dd>.true. or .false. </dd></dl>
0 commit comments