Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
NyquistBase::Tokenizer Struct Reference
Collaboration diagram for NyquistBase::Tokenizer:
[legend]

Public Member Functions

bool Tokenize (const wxString &line, bool eof, size_t trimStart, size_t trimEnd)
 

Public Attributes

bool sl { false }
 
bool q { false }
 
int paren { 0 }
 
wxString tok
 
wxArrayStringEx tokens
 

Detailed Description

Definition at line 200 of file NyquistBase.h.

Member Function Documentation

◆ Tokenize()

bool NyquistBase::Tokenizer::Tokenize ( const wxString &  line,
bool  eof,
size_t  trimStart,
size_t  trimEnd 
)

Definition at line 1960 of file NyquistBase.cpp.

1962{
1963 auto endToken = [&] {
1964 if (!tok.empty())
1965 {
1966 tokens.push_back(tok);
1967 tok = wxT("");
1968 }
1969 };
1970
1971 for (auto c :
1972 make_iterator_range(line.begin() + trimStart, line.end() - trimEnd))
1973 {
1974 if (q && !sl && c == wxT('\\'))
1975 {
1976 // begin escaped character, only within quotes
1977 sl = true;
1978 continue;
1979 }
1980
1981 if (!sl && c == wxT('"'))
1982 {
1983 // Unescaped quote
1984 if (!q)
1985 {
1986 // start of string
1987 if (!paren)
1988 // finish previous token
1989 endToken();
1990 // Include the delimiter in the token
1991 tok += c;
1992 q = true;
1993 }
1994 else
1995 {
1996 // end of string
1997 // Include the delimiter in the token
1998 tok += c;
1999 if (!paren)
2000 endToken();
2001 q = false;
2002 }
2003 }
2004 else if (!q && !paren && (c == wxT(' ') || c == wxT('\t')))
2005 // Unenclosed whitespace
2006 // Separate tokens; don't accumulate this character
2007 endToken();
2008 else if (!q && c == wxT(';'))
2009 // semicolon not in quotes, but maybe in parentheses
2010 // Lisp style comments with ; (but not with #| ... |#) are allowed
2011 // within a wrapped header multi-line, so that i18n hint comments may
2012 // be placed before strings and found by xgettext
2013 break;
2014 else if (!q && c == wxT('('))
2015 {
2016 // Start of list or sublist
2017 if (++paren == 1)
2018 // finish previous token; begin list, including the delimiter
2019 endToken(), tok += c;
2020 else
2021 // defer tokenizing of nested list to a later pass over the token
2022 tok += c;
2023 }
2024 else if (!q && c == wxT(')'))
2025 {
2026 // End of list or sublist
2027 if (--paren == 0)
2028 // finish list, including the delimiter
2029 tok += c, endToken();
2030 else if (paren < 0)
2031 // forgive unbalanced right paren
2032 paren = 0, endToken();
2033 else
2034 // nested list; deferred tokenizing
2035 tok += c;
2036 }
2037 else
2038 {
2039 if (sl && paren)
2040 // Escaped character in string inside list, to be parsed again
2041 // Put the escape back for the next pass
2042 tok += wxT('\\');
2043 if (sl && !paren && c == 'n')
2044 // Convert \n to newline, the only special escape besides \\ or \"
2045 // But this should not be used if a string needs to localize.
2046 // Instead, simply put a line break in the string.
2047 c = '\n';
2048 tok += c;
2049 }
2050
2051 sl = false;
2052 }
2053
2054 if (eof || (!q && !paren))
2055 {
2056 endToken();
2057 return true;
2058 }
2059 else
2060 {
2061 // End of line but not of file, and a string or list is yet unclosed
2062 // If a string, accumulate a newline character
2063 if (q)
2064 tok += wxT('\n');
2065 return false;
2066 }
2067}
wxT("CloseDown"))
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: IteratorX.h:210
wxArrayStringEx tokens
Definition: NyquistBase.h:206

References make_iterator_range(), paren, q, sl, tok, tokens, and wxT().

Referenced by NyquistBase::Parse(), NyquistBase::ParseChoice(), NyquistBase::ParseFileExtensions(), NyquistBase::ParseFileType(), NyquistBase::ParseFileTypes(), and NyquistBase::UnQuoteMsgid().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ paren

int NyquistBase::Tokenizer::paren { 0 }

Definition at line 204 of file NyquistBase.h.

Referenced by Tokenize().

◆ q

bool NyquistBase::Tokenizer::q { false }

Definition at line 203 of file NyquistBase.h.

Referenced by Tokenize().

◆ sl

bool NyquistBase::Tokenizer::sl { false }

Definition at line 202 of file NyquistBase.h.

Referenced by Tokenize().

◆ tok

wxString NyquistBase::Tokenizer::tok

Definition at line 205 of file NyquistBase.h.

Referenced by Tokenize().

◆ tokens

wxArrayStringEx NyquistBase::Tokenizer::tokens

The documentation for this struct was generated from the following files: