Changes in / [b1b513d:6174ecc]


Ignore:
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/fangren_yu_MMath/conclusion.tex

    rb1b513d r6174ecc  
    11\chapter{Conclusion}
    22
    3 In the past few years of development, \CFA has gone from a proof-of-concept prototype to an actual experimental language, with a few medium-sized projects written completely in \CFA included in the language's libraries ($\approx$\,45,000 lines of code).\footnote{In Fall 2024, two amazing CS343 students completed all 6 concurrent assignments in \CFA. Many small language problems were uncovered and missing features discovered; these issues are being fixed for Fall 2025.}
    4 The work done in this thesis is motivated by real needs arising from the development and testing of these projects, which often pushes the limits of \CFA's type system and compiler capabilities.
    5 While most of the previous \CFA language feature and compiler developments were done either in isolation or with limited testing, getting them to work together and with real projects is presenting significant new challenges.
    6 These challenges could have been foreseen before development and testing began in earnest.
     3The goal of this thesis is to ...
    74
    8 This work aims to identify and fix a number of practical issues of multiple \CFA type-system features and their interactions.
    9 In particular, the inclusion of reference types, tuple types, and generic structures together with rich overloading in the language makes the complexity of expression resolution much higher than in other programming languages.
    10 I significantly reworked the abstract syntax-tree representation and resolution algorithm to push the \CFA compilation time down to a practical level.
    11 The expression-cost system was also revised multiple times to make overload selection more predictable and match programmer's intuition and expectation in the majority of cases.
    12 Still, fundamental problems remain and fixing them will require significant changes to the language type-system, possibly from the ground up.
    13 
    14 As per the \CFA project motto ``describe not prescribe,'' \CFA's type system is designed to have a lot of flexibility and give programmers freedom in the usage of overloading and polymorphism.
    15 With such a complex type system, it is very difficult (sometimes even impossible) to try to have the compiler accept all the intuitively valid \CFA programs.
    16 As has been demonstrated, the \CFA programming language is still far from complete, and the primary future goal is to expand \CFA's type-resolution capability while maintaining, expressibility, decent compile-time, and excellent run-time performance.
    17 Stealing some theoretical insights of parametric polymorphism from functional programming, may also prove to be useful.
  • doc/theses/fangren_yu_MMath/resolution.tex

    rb1b513d r6174ecc  
    151151Specifically, the resolution algorithms used in \CC and Java are greedy, selecting the best match for each subexpression without considering the higher-level ones (bottom-up).
    152152Therefore, at each resolution step, the arguments are already given unique interpretations, so the ordering only needs to compare different sets of conversion targets (function parameter types) on the same set of input.
     153\begin{cfa}
     154@generate a C++ example here@
     155
     156read more
     157\end{cfa}
    153158
    154159In \CFA, trying to use such a system is problematic because of the presence of return-type overloading of functions and variable.
  • doc/theses/fangren_yu_MMath/uw-ethesis-frontpgs.tex

    rb1b513d r6174ecc  
    131131\begin{center}\textbf{Abstract}\end{center}
    132132
    133 \CFA (C-for-all) is an evolutionary extension of C programming language, which introduces many modern programming language features to C.
    134 \CFA has a type system built around parametric polymorphism, and the polymorphic functions are prefixed by a @forall@ declaration of type parameters, giving the language its name.
    135 
    136 This thesis presents a series of work on type resolution in \CFA. Every function, including the built-in C operators, can be overloaded in \CFA, therefore resolving function overloads and generic type parameters is at the heart of \CFA expression analysis. This thesis focuses on the interactions of various \CFA language features such as reference and generic types in type resolution, analyzes the known issues and presents improvements to the type system that fix those problems. Ideas for future work are also given for further improving the consistency of \CFA type system at a language design level.
     133Type resolution ...
    137134
    138135\cleardoublepage
  • doc/theses/mike_brooks_MMath/string.tex

    rb1b513d r6174ecc  
    77
    88\section{String Operations}
    9 
    10 % https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions)
    119
    1210\VRef[Figure]{f:StrApiCompare} shows a general comparison of string APIs for C, \CC, Java and \CFA.
     
    2523@strlen@                                & @length@, @size@              & @length@                      & @size@        \\
    2624@[ ]@                                   & @[ ]@                                 & @charAt@          & @[ ]@     \\
    27 @strncpy@                               & @substr@                              & @substring@       & @( )@ RHS @=@     \\
    28 @strncpy@                               & @replace@                             & @replace@         & @( )@ LHS @=@ \\
     25@strncpy@                               & @substr@                              & @substring@       & @( )@     \\
     26@strncpy@                               & @replace@                             & @replace@         & @=@ \emph{(on a substring)}\\
    2927@strstr@                                & @find@                                & @indexOf@         & @find@ \\
    3028@strcspn@                               & @find_first_of@               & @matches@         & @include@ \\
     
    6462\begin{cquote}
    6563\sf
    66 \begin{tabular}{@{}rrrrll@{}}
    67 \small\tt "a & \small\tt b & \small\tt c & \small\tt d & \small\tt e" \\
     64\begin{tabular}{@{}rrrrrl@{}}
     65\small\tt a & \small\tt b & \small\tt c & \small\tt d & \small\tt e \\
    68660 & 1 & 2 & 3 & 4 & left to right index \\
    6967-5 & -4 & -3 & -2 & -1 & right to left index
     
    7472\begin{cfa}
    7573#include @<string.hfa>@
    76 @string@ s = "abcde", name = "MIKE", digit = "0123456789";
     74@string@ s = "abcde", name = "MIKE", digit, alpha, punctuation, ifstmt;
    7775const char cs[] = "abc";
    7876int i;
    79 \end{cfa}
    80 Note, the include file @<string.hfa>@ to access type @string@.
     77digit  = "0123456789";
     78punctuation = "().,";
     79ifstmt = "IF (A > B) {";
     80\end{cfa}
     81Note, the include file @string.hfa@ to access type @string@.
    8182
    8283
     
    393394Extending the pattern to a regular expression is a possible extension.
    394395
    395 The replace operation returns a string in which all occurrences of a substring are replaced by another string.
     396
     397\subsection{Searching}
     398
     399The @index@ operation
     400\begin{cfa}
     401int index( const string & key, int start = 1, occurrence occ = first );
     402\end{cfa}
     403returns the position of the first or last occurrence of the @key@ (depending on the occurrence indicator @occ@ that is either @first@ or @last@) in the current string starting the search at position @start@.
     404If the @key@ does not appear in the current string, the length of the current string plus one is returned.
     405%If the @key@ has zero length, the value 1 is returned regardless of what the current string contains.
     406A negative starting position is a specification from the right end of the string.
    396407\begin{cquote}
    397408\setlength{\tabcolsep}{15pt}
    398409\begin{tabular}{@{}l|l@{}}
    399410\begin{cfa}
    400 s = replace( "PETER", "E", "XX" );
    401 s = replace( "PETER", "ET", "XX" );
    402 s = replace( "PETER", "W", "XX" );
    403 \end{cfa}
    404 &
    405 \begin{cfa}
    406 "PXXTXXR"
    407 "PXXER"
    408 "PETER"
     411i = find( digit, "567" );
     412i = find( digit, "567", 7 );
     413i = digit.index( "567", -1, last );
     414i = name.index( "E", 5, last );
     415\end{cfa}
     416&
     417\begin{cfa}
     4185
     41910
     420
     421
    409422\end{cfa}
    410423\end{tabular}
    411424\end{cquote}
    412 The replacement is done left-to-right and substituted text is not examined for replacement.
    413 
    414 
    415 \subsection{Searching}
    416 
    417 The find operation returns the position of the first occurrence of a key string in a string.
    418 If the key does not appear in the current string, the length of the current string plus one is returned.
    419 \begin{cquote}
    420 \setlength{\tabcolsep}{15pt}
    421 \begin{tabular}{@{}l|l@{}}
    422 \begin{cfa}
    423 i = find( digit, '3' );
    424 i = "45" ^ digit; // python style "45" in digit
    425 string x = "567";
    426 i = find( digit, x );
    427 \end{cfa}
    428 &
    429 \begin{cfa}
    430 3
    431 4
    432 
    433 5
    434 \end{cfa}
    435 \end{tabular}
    436 \end{cquote}
    437 The character-class operations indicates if a string is composed completely of a particular class of characters, \eg, alphabetic, numeric, vowels, \etc.
    438 \begin{cquote}
    439 \setlength{\tabcolsep}{15pt}
    440 \begin{tabular}{@{}l|l@{}}
    441 \begin{cfa}
    442 charclass vowels{ "aeiouy" };
    443 i = include( "aaeiuyoo", vowels );
    444 i = include( "aabiuyoo", vowels );
    445 \end{cfa}
    446 &
    447 \begin{cfa}
    448 
    449 8  // compliant
    450 2  // b non-compliant
    451 \end{cfa}
    452 \end{tabular}
    453 \end{cquote}
    454 @vowels@ defines a character class and function @include@ checks if all characters in the string are included in the class (compliance).
    455 The position of the last character plus 1 is return if the string is compliant or the position of the first non-compliant character.
    456 There is no relationship between the order of characters in the two strings.
    457 Function @exclude@ is the reverse of @include@, checking if all characters in the string are excluded from the class (compliance).
    458 \begin{cquote}
    459 \setlength{\tabcolsep}{15pt}
    460 \begin{tabular}{@{}l|l@{}}
    461 \begin{cfa}
    462 i = exclude( "cdbfghmk", vowels );
    463 i = exclude( "cdyfghmk", vowels );
    464 \end{cfa}
    465 &
    466 \begin{cfa}
    467 8  // compliant
    468 2  // y non-compliant
    469 \end{cfa}
    470 \end{tabular}
    471 \end{cquote}
    472 Both forms can return the longest substring of compliant characters.
    473 \begin{cquote}
    474 \setlength{\tabcolsep}{15pt}
    475 \begin{tabular}{@{}l|l@{}}
    476 \begin{cfa}
    477 s = include( "aaeiuyoo", vowels );
    478 s = include( "aabiuyoo", vowels );
    479 s = exclude( "cdbfghmk", vowels );
    480 s = exclude( "cdyfghmk", vowels );
    481 \end{cfa}
    482 &
    483 \begin{cfa}
    484 "aaeiuyoo"
    485 "aa"
    486 "cdbfghmk"
    487 "cd"
    488 \end{cfa}
    489 \end{tabular}
    490 \end{cquote}
    491 
    492 The test operation checks if each character in a string is in one of the C character classes.
    493 \begin{cquote}
    494 \setlength{\tabcolsep}{15pt}
    495 \begin{tabular}{@{}l|l@{}}
    496 \begin{cfa}
    497 i = test( "1FeC34aB", @isxdigit@ );
    498 i = test( ".,;'!\"", @ispunct@ );
    499 i = test( "XXXx", @isupper@ );
    500 \end{cfa}
    501 &
    502 \begin{cfa}
    503 8   // compliant
    504 6   // compliant
    505 3   // non-compliant
    506 \end{cfa}
    507 \end{tabular}
    508 \end{cquote}
    509 The position of the last character plus 1 is return if the string is compliant or the position of the first non-compliant character.
    510 
    511 Combining substring and search allows actions like trimming whitespace from the start of a line.
    512 \begin{cquote}
    513 \setlength{\tabcolsep}{15pt}
    514 \begin{tabular}{@{}l|l@{}}
    515 \begin{cfa}
    516 string line = "  \t  xxx yyy zzz";
    517 string trim = line( test( line, isspace ) );
    518 \end{cfa}
    519 &
    520 \begin{cfa}
    521 
    522 "xxx yyy zzz"
    523 \end{cfa}
    524 \end{tabular}
    525 \end{cquote}
    526 
    527 The translate operation returns a string with each character transformed by one of the C character transformation functions.
    528 \begin{cquote}
    529 \setlength{\tabcolsep}{15pt}
    530 \begin{tabular}{@{}l|l@{}}
    531 \begin{cfa}
    532 s = translate( "abc", @toupper@ );
    533 s = translate( "ABC", @tolower@ );
    534 int tospace( int c ) { return isspace( c ) ? ' ' : c; }
    535 s = translate( "X X\tX\nX", @tospace@ );
    536 \end{cfa}
    537 &
    538 \begin{cfa}
    539 "ABC"
    540 "abc"
    541 
    542 "X X X X"
    543 \end{cfa}
    544 \end{tabular}
    545 \end{cquote}
     425The next two string operations test a string to see if it is or is not composed completely of a particular class of characters.
     426For example, are the characters of a string all alphabetic or all numeric?
     427Use of these operations involves a two step operation.
     428First, it is necessary to create an instance of type @strmask@ and initialize it to a string containing the characters of the particular character class, as in:
     429\begin{cfa}
     430strmask digitmask = digit;
     431strmask alphamask = string( "abcdefghijklmnopqrstuvwxyz" );
     432\end{cfa}
     433Second, the character mask is used in the functions @include@ and @exclude@ to check a string for compliance of its characters with the characters indicated by the mask.
     434
     435The @include@ operation
     436\begin{cfa}
     437int include( const strmask &, int = 1, occurrence occ = first );
     438\end{cfa}
     439returns the position of the first or last character (depending on the occurrence indicator, which is either @first@ or @last@) in the current string that does not appear in the @mask@ starting the search at position @start@;
     440hence it skips over characters in the current string that are included (in) the @mask@.
     441The characters in the current string do not have to be in the same order as the @mask@.
     442If all the characters in the current string appear in the @mask@, the length of the current string plus one is returned, regardless of which occurrence is being searched for.
     443A negative starting position is a specification from the right end of the string.
     444\begin{cfa}
     445i = name.include( digitmask );          $\C{// i is assigned 1}$
     446i = name.include( alphamask );          $\C{// i is assigned 6}$
     447\end{cfa}
     448
     449The @exclude@ operation
     450\begin{cfa}
     451int exclude( string &mask, int start = 1, occurrence occ = first )
     452\end{cfa}
     453returns the position of the first or last character (depending on the occurrence indicator, which is either @first@ or @last@) in the current string that does appear in the @mask@ string starting the search at position @start@;
     454hence it skips over characters in the current string that are excluded from (not in) in the @mask@ string.
     455The characters in the current string do not have to be in the same order as the @mask@ string.
     456If all the characters in the current string do NOT appear in the @mask@ string, the length of the current string plus one is returned, regardless of which occurrence is being searched for.
     457A negative starting position is a specification from the right end of the string.
     458\begin{cfa}
     459i = name.exclude( digitmask );          $\C{// i is assigned 6}$
     460i = ifstmt.exclude( strmask( punctuation ) ); $\C{// i is assigned 4}$
     461\end{cfa}
     462
     463The @includeStr@ operation:
     464\begin{cfa}
     465string includeStr( strmask &mask, int start = 1, occurrence occ = first )
     466\end{cfa}
     467returns the longest substring of leading or trailing characters (depending on the occurrence indicator, which is either @first@ or @last@) of the current string that ARE included in the @mask@ string starting the search at position @start@.
     468A negative starting position is a specification from the right end of the string.
     469\begin{cfa}
     470s = name.includeStr( alphamask );       $\C{// s is assigned "MIKE"}$
     471s = ifstmt.includeStr( alphamask );     $\C{// s is assigned "IF"}$
     472s = name.includeStr( digitmask );       $\C{// s is assigned ""}$
     473\end{cfa}
     474
     475The @excludeStr@ operation:
     476\begin{cfa}
     477string excludeStr( strmask &mask, int start = 1, occurrence = first )
     478\end{cfa}
     479returns the longest substring of leading or trailing characters (depending on the occurrence indicator, which is either @first@ or @last@) of the current string that are excluded (NOT) in the @mask@ string starting the search at position @start@.
     480A negative starting position is a specification from the right end of the string.
     481\begin{cfa}
     482s = name.excludeStr( digitmask);        $\C{// s is assigned "MIKE"}$
     483s = ifstmt.excludeStr( strmask( punctuation ) ); $\C{// s is assigned "IF "}$
     484s = name.excludeStr( alphamask);        $\C{// s is assigned ""}$
     485\end{cfa}
     486
     487
     488\subsection{Miscellaneous}
     489
     490The @trim@ operation
     491\begin{cfa}
     492string trim( string &mask, occurrence occ = first )
     493\end{cfa}
     494returns a string in that is the longest substring of leading or trailing characters (depending on the occurrence indicator, which is either @first@ or @last@) which ARE included in the @mask@ are removed.
     495\begin{cfa}
     496// remove leading blanks
     497s = string( "   ABC" ).trim( " " );     $\C{// s is assigned "ABC",}$
     498// remove trailing blanks
     499s = string( "ABC   " ).trim( " ", last ); $\C{// s is assigned "ABC",}$
     500\end{cfa}
     501
     502The @translate@ operation
     503\begin{cfa}
     504string translate( string &from, string &to )
     505\end{cfa}
     506returns a string that is the same length as the original string in which all occurrences of the characters that appear in the @from@ string have been translated into their corresponding character in the @to@ string.
     507Translation is done on a character by character basis between the @from@ and @to@ strings; hence these two strings must be the same length.
     508If a character in the original string does not appear in the @from@ string, then it simply appears as is in the resulting string.
     509\begin{cfa}
     510// upper to lower case
     511name = name.translate( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz" );
     512                        // name is assigned "name"
     513s = ifstmt.translate( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz" );
     514                        // ifstmt is assigned "if (a > b) {"
     515// lower to upper case
     516name = name.translate( "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
     517                        // name is assigned "MIKE"
     518\end{cfa}
     519
     520The @replace@ operation
     521\begin{cfa}
     522string replace( string &from, string &to )
     523\end{cfa}
     524returns a string in which all occurrences of the @from@ string in the current string have been replaced by the @to@ string.
     525\begin{cfa}
     526s = name.replace( "E", "XX" );          $\C{// s is assigned "PXXTXXR"}$
     527\end{cfa}
     528The replacement is done left-to-right.
     529When an instance of the @from@ string is found and changed to the @to@ string, it is NOT examined again for further replacement.
    546530
    547531
  • libcfa/src/collections/string.cfa

    rb1b513d r6174ecc  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr  9 22:27:40 2025
    13 // Update Count     : 368
     12// Last Modified On : Sat Apr  5 15:18:30 2025
     13// Update Count     : 318
    1414//
    1515
     
    295295bool ?<? ( const char * s1, const string & s2 ) { return s1 <  *s2.inner; }
    296296
     297
     298////////////////////////////////////////////////////////
     299// Getter
     300
     301size_t len( const string & s ) {
     302        return len( *s.inner );
     303}
     304
    297305////////////////////////////////////////////////////////
    298306// Concatenation
     
    416424}
    417425
    418 size_t find( const string & s, size_t start, size_t len, const string & key, size_t kstart, size_t klen ) {
     426int find( const string & s, size_t start, size_t len, const string & key, size_t kstart, size_t klen ) {
    419427        if ( start < 0 ) { start += len( s ); }
    420428        if ( len < 0 ) { len = -len; start -= len; }
     
    426434        if ( kstart >= len( key ) ) return 0;
    427435        if ( kstart + klen > len( key ) ) klen = len( key ) - kstart;
    428 
     436       
    429437        return findFrom( *s.inner, start, *key.inner );
    430438}
    431439
    432 size_t find( const string & s, char key ) {
     440int find( const string & s, char key ) {
    433441        return find( *s.inner, key );
    434442}
    435443
    436 size_t find( const string & s, const string & key ) {
     444int find( const string & s, const string & key ) {
    437445        return find( *s.inner, *key.inner );
    438446}
    439447
    440 size_t find( const string & s, const char * key ) {
     448int find( const string & s, const char * key ) {
    441449        return find( *s.inner, key );
    442450}
    443451
    444 size_t find( const string & s, const char * key, size_t keysize ) {
     452int find( const string & s, const char * key, size_t keysize ) {
    445453        return find( *s.inner, key, keysize );
    446454}
    447455
    448 size_t find( const string & s, size_t start, char key ) {
     456int find( const string & s, size_t start, char key ) {
    449457        return findFrom( *s.inner, start, key );
    450458}
    451459
    452 size_t find( const string & s, size_t start, const char * key ) {
     460int find( const string & s, size_t start, const char * key ) {
    453461        return findFrom( *s.inner, start, key );
    454462}
    455463
    456 size_t find( const string & s, size_t start, const char * key, size_t keysize ) {
     464int find( const string & s, size_t start, const char * key, size_t keysize ) {
    457465        return findFrom( *s.inner, start, key, keysize );
    458466}
     
    519527}
    520528
    521 size_t exclude( const string & s, const charclass & mask ) {
     529
     530int exclude( const string & s, const charclass & mask ) {
    522531        return exclude( *s.inner, *mask.inner );
    523532}
    524 
    525 size_t include( const string & s, const charclass & mask ) {
     533/*
     534StrSlice exclude( string & s, const charclass & mask ) {
     535}
     536*/
     537
     538int include( const string & s, const charclass & mask ) {
    526539        return include( *s.inner, *mask.inner );
    527540}
    528541
    529 size_t test( const string & s, int (*f)( int ) ) {
    530         size_t l = len( s );
    531         for ( i; l ) {
    532                 if ( ! f( s[i] ) ) return i;
    533         } // for
    534         return l;
    535 }
    536 
    537 string replace( string & s, const string & from, const string & to ) {
    538         ssize_t pos;
    539     string r;
    540 
    541     pos = find( s, from );
    542     if ( pos < len( s ) ) {
    543                 r = s( 0, pos ) + to + replace( s( pos + (ssize_t)len( from ) ), from, to );
    544                 string front = s( 0, pos );
    545                 string back = s( pos + (ssize_t)len( from ) );
    546                 r = front + to + replace( back, from, to );
    547     } else {
    548                 r = s;
    549     } // if
    550     return r;
    551 }
    552 
    553 string translate( const string & s, int (*f)( int ) ) {
    554         string r = s;
    555         size_t l = len( r );
    556         for ( i; l ) {
    557                 r[i] = (char)f( r[i] );
    558         } // for
    559         return r;
    560 }
     542/*
     543StrSlice include( string & s, const charclass & mask ) {
     544}
     545*/
  • libcfa/src/collections/string.hfa

    rb1b513d r6174ecc  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr  9 22:27:41 2025
    13 // Update Count     : 259
     12// Last Modified On : Sat Apr  5 15:16:23 2025
     13// Update Count     : 180
    1414//
    1515
     
    1717
    1818#include <fstream.hfa>
    19 #include <string_res.hfa>
     19
     20
     21// in string_res.hfa
     22struct string_res;
     23struct charclass_res;
    2024
    2125struct string {
     
    2428
    2529// Getters
    26 static inline size_t len( const string & s ) { return len( *s.inner ); }
    2730static inline size_t len( const char * cs ) { return strlen( cs ); };
     31size_t len( const string & s );
    2832static inline size_t strlen( const string & s ) { return len( s ); }
    2933
     
    211215bool contains( const string & s, char ch );                             // single character
    212216
    213 //int find( const string & s, size_t start, size_t len, const string & key, size_t kstart, size_t klen );
    214 size_t find$( const string_res & s, size_t start, size_t len, const string & key_res, size_t kstart, size_t klen );
    215 
    216 size_t find( const string & s, char key );
    217 size_t find( const string & s, const char * key );
    218 size_t find( const string & s, const string & key );
    219 size_t find( const string & s, const char * key, size_t keysize );
    220 
    221 size_t find( const string & s, size_t start, char key );
    222 size_t find( const string & s, size_t start, const string & key );
    223 size_t find( const string & s, size_t start, const char * key );
    224 size_t find( const string & s, size_t start, const char * key, size_t keysize );
    225 static inline ?^?( const string & key, const string & s ) { return find( s, key ); }
    226 static inline ?^?( const char * key, const string & s ) { return find( s, key ); }
     217int find( const string & s, char key );
     218static inline int ?^? ( const string & s, char key ) { return find( s, key ); }
     219int find( const string & s, const char * key );
     220static inline int ?^? ( const string & s, const char * key ) { return find( s, key ); }
     221int find( const string & s, const string & key );
     222static inline int ?^? ( const string & s, const string & key ) { return find( s, key ); }
     223int find( const string & s, const char * key, size_t keysize );
     224
     225int find( const string & s, size_t start, char key );
     226int find( const string & s, size_t start, const string & key );
     227int find( const string & s, size_t start, const char * key );
     228int find( const string & s, size_t start, const char * key, size_t keysize );
    227229
    228230bool includes( const string & s, const string & mask );
     
    239241
    240242// Slicing
    241 string ?()( string & s, ssize_t start, ssize_t len );
    242 static inline string ?()( const string & s, ssize_t start, ssize_t len ) { string & w = (string &)s; return w( start, len ); } // FIX ME
     243string ?()( string & s, ssize_t start, ssize_t len );           // TODO const?
    243244string ?()( string & s, ssize_t start );
    244 static inline string ?()( const string & s, ssize_t start ) { string & w = (string &)s; return w( start ); } // FIX ME
    245245static inline string ?()( string & s, char m ) { return s( find( s, m ), 1 )`share; }
    246 static inline string ?()( const string & s, char m ) { string & w = (string &)s; return w( find( s, m ), 1 )`share; } // FIX ME
    247246static inline string ?()( string & s, const char * m ) { return s( find( s, m ), len( m ) )`share; }
    248 static inline string ?()( const string & s, const char * m ) { string & w = (string &)s; return w( find( s, m ), len( m ) )`share; } // FIX ME
    249247static inline string ?()( string & s, const string & m ) { return s( find( s, m ), len( m ) )`share; }
    250 static inline string ?()( const string & s, const string & m ) { string & w = (string &)s; return w( find( s, m ), len( m ) )`share; } // FIX ME
     248
     249// Modifiers
     250void padStart( string & s, size_t n );
     251void padStart( string & s, size_t n, char padding );
     252void padEnd( string & s, size_t n );
     253void padEnd( string & s, size_t n, char padding );
     254
    251255
    252256struct charclass {
     
    263267void ^?{}( charclass & );
    264268
    265 size_t include( const string & s, const charclass & mask );
    266 static inline size_t include( const char * s, const charclass & mask ) { string temp = s; return include( temp, mask ); }
    267 static inline string include( const string & s, const charclass & mask ) { ssize_t i = include( s, mask ); return s( 0, i )`share; }
    268 static inline string include( const char * s, const charclass & mask ) { string temp = s; ssize_t i = include( temp, mask ); return temp( 0, i ); }
    269 
    270 size_t exclude( const string & s, const charclass & mask );
    271 static inline size_t exclude( const char * s, const charclass & mask ) { string temp = s; return exclude( temp, mask ); }
    272 static inline string exclude( const string & s, const charclass & mask ) { ssize_t i = exclude( s, mask ); return s( 0, i )`share; }
    273 static inline string exclude( const char * s, const charclass & mask ) { string temp = s; ssize_t i = exclude( temp, mask ); return temp( 0, i ); }
    274 
    275 size_t test( const string & s, int (*f)( int ) );
    276 static inline size_t test( const char * c, int (*f)( int ) ) {
    277         const string S = c;
    278         return test( S, f );
    279 }
    280 
    281 string replace( string & s, const string & from, const string & to );
    282 static inline string replace( const char * s, const char * from, const char * to ) {
    283         string S = s, From = from, To = to;
    284         return replace( S, From, To );
    285 }
    286 static inline string replace( string & s, const char * from, const char * to ) {
    287         string From = from, To = to;
    288         return replace( s, From, To );
    289 }
    290 static inline string replace( string & s, const char * from, const string & to ) {
    291         string From = from;
    292         return replace( s, From, to );
    293 }
    294 static inline string replace( string & s, string & from, const char * to ) {
    295         string To = to;
    296         return replace( s, from, To );
    297 }
    298 
    299 string translate( const string & s, int (*f)( int ) );
    300 static inline string translate( const char * c, int (*f)( int ) ) {
    301         const string S = c;
    302         return translate( S, f );
    303 }
     269int include( const string & s, const charclass & mask );
     270
     271int exclude( const string & s, const charclass & mask );
     272
     273/*
     274What to do with?
     275StrRet include( string & s, const charclass & mask );
     276StrRet exclude( string & s, const charclass & mask );
     277*/
  • libcfa/src/collections/string_res.cfa

    rb1b513d r6174ecc  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr  9 08:44:17 2025
    13 // Update Count     : 128
     12// Last Modified On : Sun Apr  6 07:38:02 2025
     13// Update Count     : 111
    1414//
    1515
     
    190190const char * DEBUG_string_heap_start( VbyteHeap * heap ) {
    191191        return heap->StartVbyte;
     192}
     193
     194// Returns the size of the string in bytes
     195size_t len(const string_res & s) with(s) {
     196        return Handle.lnth;
    192197}
    193198
     
    751756}
    752757
    753 // int find$( const string_res & s, ssize_t start, ssize_t len, const string_res & k, ssize_t kstart, ssize_t klen ) {
    754 //     if ( start < 0 ) start = s.Handle.lnth + start;          // adjust negative starting locations
    755 //     if ( kstart < 0 ) kstart = k.Handle.lnth + kstart;
    756 
    757 //      if ( start + len > s.Handle.lnth ) return start + 1;  // cannot be there
    758 //      if ( kstart + len > k.Handle.lnth ) return start + 1;
    759 //      if ( klen > len ) return start + 1;
    760 
    761 //      int i, r;
    762 
    763 //      for ( i = max( start, 1 ); ; i += 1 ) {
    764 //              if ( i > s.Handle.lnth - k.Handle.lnth + 1 ) {
    765 //                      r = s.Handle.lnth + 1;
    766 //                      break;
    767 //          } // exit
    768 //              if ( HeapArea->ByteCmp( s.Handle.s, i, k.Handle.lnth, k.Handle.s, 1, k.Handle.lnth ) == 0 ) {
    769 //                      r = i;
    770 //                      break;
    771 //          } // exit
    772 //      } // for
    773 //      return r;
    774 // }
    775 
    776 int find( const string_res & s, char search ) {
     758int find(const string_res & s, char search) {
    777759        return findFrom(s, 0, search);
    778760}
    779761
    780 int findFrom( const string_res & s, size_t fromPos, char search ) {
     762int findFrom(const string_res & s, size_t fromPos, char search) {
    781763        // FIXME: This paricular overload (find of single char) is optimized to use memchr.
    782764        // The general overload (find of string, memchr applying to its first character) and `contains` should be adjusted to match.
  • libcfa/src/collections/string_res.hfa

    rb1b513d r6174ecc  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr  9 15:16:29 2025
    13 // Update Count     : 76
     12// Last Modified On : Sun Apr  6 07:35:44 2025
     13// Update Count     : 70
    1414//
    1515
     
    7070
    7171// Getters
    72 static inline size_t len( const string_res & s ) { return s.Handle.lnth; }
     72size_t len( const string_res & s);
    7373
    7474// Constructors, Assignment Operators, Destructor
     
    220220bool contains( const string_res & s, char ch); // single character
    221221
    222 int find$( const string_res & s, ssize_t start, ssize_t len, const string_res & key, ssize_t kstart, ssize_t klen );
    223 
    224222int find( const string_res & s, char search);
    225223int find( const string_res & s, const string_res & search);
     
    247245int exclude( const string_res & s, const charclass_res & mask);
    248246
     247// Modifiers
     248void padStart(string_res & s, size_t n);
     249void padStart(string_res & s, size_t n, char padding);
     250void padEnd(string_res & s, size_t n);
     251void padEnd(string_res &s, size_t n, char padding);
     252
  • tests/collections/.expect/string-api-coverage.txt

    rb1b513d r6174ecc  
    8585true false true false true true true false true false
    86863 0 0 11 26 0
    87 abc   abcdefghijk abcdefghijklmnopqrstuvwxyz
  • tests/collections/string-api-coverage.cfa

    rb1b513d r6174ecc  
    392392
    393393    sout
    394         | (return size_t)include( alphabet, cc_cba )  // 3
    395         | (return size_t)exclude( alphabet, cc_cba )  // 0
    396         | (return size_t)include( alphabet, cc_onml )  // 0
    397         | (return size_t)exclude( alphabet, cc_onml )  // 11
    398         | (return size_t)include( alphabet, cc_alphabet )  // 26
    399         | (return size_t)exclude( alphabet, cc_alphabet ); // 0
    400 
    401     sout
    402         | (return string)include( alphabet, cc_cba )  // "abc"
    403         | (return string)exclude( alphabet, cc_cba )  // ""
    404         | (return string)include( alphabet, cc_onml )  // ""
    405         | (return string)exclude( alphabet, cc_onml )  // "abcdefghijk"
    406         | (return string)include( alphabet, cc_alphabet )  // "abcdefghijklmnopqrstuvwxyz"
    407         | (return string)exclude( alphabet, cc_alphabet ); // ""
     394        | include( alphabet, cc_cba )  // 3
     395        | exclude( alphabet, cc_cba )  // 0
     396        | include( alphabet, cc_onml )  // 0
     397        | exclude( alphabet, cc_onml )  // 11
     398        | include( alphabet, cc_alphabet )  // 26
     399        | exclude( alphabet, cc_alphabet ); // 0
    408400}
     401
Note: See TracChangeset for help on using the changeset viewer.