| 16966 | |
| 16967 | |
| 16968 | LPTSTR TokenToString(ExprTokenType &aToken, LPTSTR aBuf, size_t *aLength) |
| 16969 | // Returns "" on failure to simplify logic in callers. Otherwise, it returns either aBuf (if aBuf was needed |
| 16970 | // for the conversion) or the token's own string. aBuf may be NULL, in which case the caller presumably knows |
| 16971 | // that this token is SYM_STRING or SYM_VAR (or the caller wants "" back for anything other than those). |
| 16972 | // If aBuf is not NULL, caller has ensured that aBuf is at least MAX_NUMBER_SIZE in size. |
| 16973 | { |
| 16974 | LPTSTR result; |
| 16975 | switch (aToken.symbol) |
| 16976 | { |
| 16977 | case SYM_VAR: // Caller has ensured that any SYM_VAR's Type() is VAR_NORMAL. |
| 16978 | result = aToken.var->Contents(); // Contents() vs. mCharContents in case mCharContents needs to be updated by Contents(). |
| 16979 | if (aLength) |
| 16980 | *aLength = aToken.var->Length(); |
| 16981 | return result; |
| 16982 | case SYM_STRING: |
| 16983 | result = aToken.marker; |
| 16984 | if (aLength) |
| 16985 | { |
| 16986 | if (aToken.marker_length == -1) |
| 16987 | break; // Call _tcslen(result) below. |
| 16988 | *aLength = aToken.marker_length; |
| 16989 | } |
| 16990 | return result; |
| 16991 | case SYM_INTEGER: |
| 16992 | result = aBuf ? ITOA64(aToken.value_int64, aBuf) : _T(""); |
| 16993 | break; |
| 16994 | case SYM_FLOAT: |
| 16995 | if (aBuf) |
| 16996 | { |
| 16997 | int length = FTOA(aToken.value_double, aBuf, MAX_NUMBER_SIZE); |
| 16998 | if (aLength) |
| 16999 | *aLength = length; |
| 17000 | return aBuf; |
| 17001 | } |
| 17002 | //else continue on to return the default at the bottom. |
| 17003 | //case SYM_OBJECT: // Treat objects as empty strings (or TRUE where appropriate). |
| 17004 | default: |
| 17005 | result = _T(""); |
| 17006 | } |
| 17007 | if (aLength) // Caller wants to know the string's length as well. |
| 17008 | *aLength = _tcslen(result); |
| 17009 | return result; |
| 17010 | } |
| 17011 | |
| 17012 | |
| 17013 |
no test coverage detected