|
7 | 7 | #include once "fbint.bi" |
8 | 8 | #include once "dstr.bi" |
9 | 9 |
|
| 10 | +#if sizeof(wstring) = 4 |
| 11 | + type WSTRING_CHAR as ulong |
| 12 | +#elseif sizeof(wstring) = 2 |
| 13 | + type WSTRING_CHAR as ushort |
| 14 | +#else |
| 15 | + type WSTRING_CHAR as ubyte |
| 16 | +#endif |
| 17 | + |
10 | 18 | ''::::: |
11 | 19 | #macro ASSIGN_SETUP(dst, src, _type) |
12 | 20 | dim as integer dst_len, src_len |
@@ -1321,6 +1329,45 @@ function hStr2long( byref txt as string, byref value as long ) as integer |
1321 | 1329 | return (*s = CHAR_NULL) |
1322 | 1330 | end function |
1323 | 1331 |
|
| 1332 | +function hWStr2long( byref txt as wstring, byref value as long ) as integer |
| 1333 | + '' could we not use VALINT() or some variation from rtlib? |
| 1334 | + |
| 1335 | + const CHAR_ZERO = asc("0") |
| 1336 | + |
| 1337 | + dim nvalue as long = 0 |
| 1338 | + dim nsign as long = 1 |
| 1339 | + |
| 1340 | + if( len( txt ) = 0 ) then |
| 1341 | + return FALSE |
| 1342 | + end if |
| 1343 | + |
| 1344 | + dim s as WSTRING_CHAR ptr = strptr(txt) |
| 1345 | + |
| 1346 | + if( s = NULL orelse *s = CHAR_NULL ) then |
| 1347 | + return FALSE |
| 1348 | + end if |
| 1349 | + |
| 1350 | + if( *s = CHAR_MINUS ) then |
| 1351 | + nsign = -1 |
| 1352 | + s += 1 |
| 1353 | + end if |
| 1354 | + |
| 1355 | + if( *s = CHAR_NULL ) then |
| 1356 | + return FALSE |
| 1357 | + end if |
| 1358 | + |
| 1359 | + while( hIsCharNumeric(*s) ) |
| 1360 | + nvalue *= 10 |
| 1361 | + nvalue += (*s - CHAR_ZERO) |
| 1362 | + s += 1 |
| 1363 | + wend |
| 1364 | + |
| 1365 | + value = nvalue * nsign |
| 1366 | + |
| 1367 | + '' return TRUE if we read the entire string |
| 1368 | + return (*s = CHAR_NULL) |
| 1369 | +end function |
| 1370 | + |
1324 | 1371 | ''::::: |
1325 | 1372 | sub hSplitStr(byref txt as string, byref del as string, res() as string) |
1326 | 1373 |
|
@@ -1424,7 +1471,7 @@ end function |
1424 | 1471 | ''::::: |
1425 | 1472 | function hStr2Args( byval txt as const zstring ptr, res() as string ) as integer |
1426 | 1473 |
|
1427 | | - '' !!!TODO!!! add the wstring version |
| 1474 | + '' add the string version |
1428 | 1475 |
|
1429 | 1476 | dim as integer t = 0 |
1430 | 1477 | dim as const ubyte ptr s = cast(const ubyte ptr, txt) |
@@ -1585,3 +1632,167 @@ function hStr2Args( byval txt as const zstring ptr, res() as string ) as integer |
1585 | 1632 | function = t |
1586 | 1633 |
|
1587 | 1634 | end function |
| 1635 | + |
| 1636 | +''::::: |
| 1637 | +function hWStr2Args( byval txt as const wstring ptr, res() as DWSTRING ) as integer |
| 1638 | + |
| 1639 | + dim as integer t = 0 |
| 1640 | + dim as const WSTRING_CHAR ptr s = cast(const WSTRING_CHAR ptr, txt) |
| 1641 | + |
| 1642 | + dim as integer prntcnt = 0 |
| 1643 | + dim as uinteger c = CHAR_NULL |
| 1644 | + dim as integer max_t = 10 |
| 1645 | + |
| 1646 | + if( txt = NULl ) then |
| 1647 | + return 0 |
| 1648 | + end if |
| 1649 | + |
| 1650 | + #define PeekChar() cast( uinteger, s[0] ) |
| 1651 | + #define SkipChar() s += 1 |
| 1652 | + #define ReadChar(c) DWstrConcatAssign( res(t-1), wchr(c) ) : s += 1 |
| 1653 | + |
| 1654 | + redim res( 0 to max_t-1 ) as DWSTRING |
| 1655 | + |
| 1656 | + do |
| 1657 | + c = PeekChar() |
| 1658 | + if (c = CHAR_TAB) or (c = CHAR_SPACE) then |
| 1659 | + SkipChar() |
| 1660 | + else |
| 1661 | + exit do |
| 1662 | + end if |
| 1663 | + loop |
| 1664 | + |
| 1665 | + '' no arguments? |
| 1666 | + if( c = CHAR_NULL ) then |
| 1667 | + return 0 |
| 1668 | + end if |
| 1669 | + |
| 1670 | + '' ok, there's at least one argument |
| 1671 | + t += 1 |
| 1672 | + |
| 1673 | + '' scan for arguments |
| 1674 | + do |
| 1675 | + c = PeekChar() |
| 1676 | + select case c |
| 1677 | + case CHAR_NULL |
| 1678 | + exit do |
| 1679 | + |
| 1680 | + case CHAR_LPRNT |
| 1681 | + prntcnt += 1 |
| 1682 | + |
| 1683 | + case CHAR_RPRNT |
| 1684 | + if( prntcnt > 0 ) then |
| 1685 | + prntcnt -= 1 |
| 1686 | + end if |
| 1687 | + |
| 1688 | + case CHAR_COMMA |
| 1689 | + if( prntcnt = 0 ) then |
| 1690 | + t += 1 |
| 1691 | + if( t > max_t ) then |
| 1692 | + max_t += 10 |
| 1693 | + redim preserve res( 0 to max_t - 1 ) |
| 1694 | + end if |
| 1695 | + SkipChar() |
| 1696 | + continue do |
| 1697 | + end if |
| 1698 | + |
| 1699 | + case CHAR_QUOTE, CHAR_EXCL, CHAR_DOLAR |
| 1700 | + dim as integer escaped = env.opt.escapestr |
| 1701 | + if( c <> CHAR_QUOTE ) then |
| 1702 | + escaped = ( c = CHAR_EXCL ) |
| 1703 | + |
| 1704 | + '' '!' | '$' |
| 1705 | + ReadChar(c) |
| 1706 | + c = PeekChar() |
| 1707 | + if( c <> CHAR_QUOTE ) then |
| 1708 | + continue do |
| 1709 | + end if |
| 1710 | + |
| 1711 | + end if |
| 1712 | + |
| 1713 | + '' '"' |
| 1714 | + ReadChar(c) |
| 1715 | + |
| 1716 | + do |
| 1717 | + c = PeekChar() |
| 1718 | + if( c = CHAR_NULL ) then |
| 1719 | + exit do |
| 1720 | + end if |
| 1721 | + |
| 1722 | + '' '"' | '\\' | any other string char |
| 1723 | + ReadChar(c) |
| 1724 | + if( c = CHAR_QUOTE ) then |
| 1725 | + |
| 1726 | + c = PeekChar() |
| 1727 | + if( c <> CHAR_QUOTE ) then |
| 1728 | + exit do |
| 1729 | + end if |
| 1730 | + |
| 1731 | + '' '"' |
| 1732 | + ReadChar(c) |
| 1733 | + |
| 1734 | + elseif( c = CHAR_RSLASH ) then |
| 1735 | + |
| 1736 | + c = PeekChar() |
| 1737 | + select case c |
| 1738 | + case CHAR_QUOTE, CHAR_RSLASH |
| 1739 | + '' '"' | '\\' |
| 1740 | + ReadChar(c) |
| 1741 | + end select |
| 1742 | + |
| 1743 | + end if |
| 1744 | + loop |
| 1745 | + continue do |
| 1746 | + |
| 1747 | + case CHAR_SLASH |
| 1748 | + |
| 1749 | + '' '/' |
| 1750 | + ReadChar(c) |
| 1751 | + |
| 1752 | + c = PeekChar() |
| 1753 | + if( c <> CHAR_APOST ) then |
| 1754 | + continue do |
| 1755 | + end if |
| 1756 | + |
| 1757 | + '' ''' |
| 1758 | + ReadChar(c) |
| 1759 | + |
| 1760 | + do |
| 1761 | + c = PeekChar() |
| 1762 | + if( c = CHAR_NULL ) then |
| 1763 | + exit do |
| 1764 | + end if |
| 1765 | + |
| 1766 | + '' ''' | any other comment char |
| 1767 | + ReadChar(c) |
| 1768 | + |
| 1769 | + if( c = CHAR_APOST ) then |
| 1770 | + c = PeekChar() |
| 1771 | + if( c = CHAR_SLASH ) then |
| 1772 | + '' '/' |
| 1773 | + ReadChar(c) |
| 1774 | + exit do |
| 1775 | + end if |
| 1776 | + end if |
| 1777 | + |
| 1778 | + loop |
| 1779 | + continue do |
| 1780 | + |
| 1781 | + case CHAR_APOST |
| 1782 | + while( c <> CHAR_NULL ) |
| 1783 | + '' ''' or any comment char to end of line |
| 1784 | + ReadChar(c) |
| 1785 | + c = PeekChar() |
| 1786 | + wend |
| 1787 | + exit do |
| 1788 | + |
| 1789 | + end select |
| 1790 | + |
| 1791 | + '' any other char not handled above |
| 1792 | + ReadChar(c) |
| 1793 | + |
| 1794 | + loop |
| 1795 | + |
| 1796 | + function = t |
| 1797 | + |
| 1798 | +end function |
0 commit comments