home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / DSTRING.CPP < prev    next >
C/C++ Source or Header  |  1997-01-16  |  25KB  |  871 lines

  1. //---------------------------------------------------------------------------
  2. //    dstring.cpp - support for delphi strings in cpp
  3. //---------------------------------------------------------------------------
  4. // $Revision:   1.32  $
  5. //-------------------------------------------------------------------------
  6. //    copyright (c) 1996 Borland International
  7. //----------------------------------------------------------------------------
  8. #pragma inline
  9.  
  10. // PRONTO_NAMESPACES must be defined when .HPP headers were generated
  11. // with namespace enabled.. //!BB
  12. //
  13. // #define PRONTO_NAMESPACES
  14.  
  15. #include <windows.hpp>
  16. #include <sysutils.hpp>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <dstring.h>
  20.  
  21. #ifdef near
  22. #undef near
  23. #endif
  24.  
  25. #if defined(PRONTO_NAMESPACES)
  26. namespace System
  27. {
  28. #endif
  29.  
  30.  
  31. //---------------------------------------------------------------------------
  32. __fastcall      AnsiString::AnsiString(const char*)
  33. {
  34.     asm
  35.     {
  36. #if defined(PRONTO_NAMESPACES)
  37.         extrn   @System@@LStrFromPChar$qqrv:near
  38. #else
  39.         extrn   @@LStrFromPChar$qqrv:near
  40. #endif
  41.         xor     ecx,ecx
  42.         mov     eax, this
  43.         mov     [eax], ecx
  44. #if defined(PRONTO_NAMESPACES)
  45.         call    @System@@LStrFromPChar$qqrv
  46. #else
  47.         call    @@LStrFromPChar$qqrv
  48. #endif
  49.     }
  50. }
  51. //---------------------------------------------------------------------------
  52. __fastcall      AnsiString::AnsiString(const AnsiString&)
  53. {
  54.     asm
  55.     {
  56. #if defined(PRONTO_NAMESPACES)
  57.         extrn   @System@@LStrAsg$qqrv:near
  58. #else
  59.         extrn   @@LStrAsg$qqrv:near
  60. #endif
  61.         mov     edx,[edx]  //!JK Do this first, Peter is relying on this!
  62.         xor     ecx,ecx
  63.         mov     eax, this
  64.         mov     [eax],ecx
  65. #if defined(PRONTO_NAMESPACES)
  66.         call    @System@@LStrAsg$qqrv
  67. #else
  68.         call    @@LStrAsg$qqrv
  69. #endif
  70.     }
  71. }
  72. //---------------------------------------------------------------------------
  73. __fastcall AnsiString::AnsiString(const char*, unsigned char len)
  74. {
  75.     asm
  76.     {
  77. #if defined(PRONTO_NAMESPACES)
  78.         extrn   @System@@LStrFromArray$qqrv:near
  79. #else
  80.         extrn   @@LStrFromArray$qqrv:near
  81. #endif
  82.         xor     ecx,ecx
  83.         mov     eax, this
  84.         mov     [eax],ecx
  85.         mov     cl, len
  86. #if defined(PRONTO_NAMESPACES)
  87.         call    @System@@LStrFromArray$qqrv
  88. #else
  89.         call    @@LStrFromArray$qqrv
  90. #endif
  91.     }
  92. }
  93. //---------------------------------------------------------------------------
  94. __fastcall AnsiString::AnsiString(const wchar_t* src)
  95. {
  96.     int len = WideCharToMultiByte(CP_ACP, 0, const_cast<wchar_t*>(src), -1, 0,
  97.       0, 0, 0);
  98.  
  99.     if (len == 1)
  100.         Data = 0;
  101.     else
  102.     {
  103.         char* buffer = new char[len];
  104.         len = WideCharToMultiByte(CP_ACP, 0, const_cast<wchar_t*>(src), -1,
  105.           buffer, len, 0, 0);
  106.         asm
  107.         {
  108. #if defined(PRONTO_NAMESPACES)
  109.             extrn   @System@@LStrFromArray$qqrv:near
  110. #else
  111.             extrn   @@LStrFromArray$qqrv:near
  112. #endif
  113.             mov     eax, this
  114.             xor     ecx,ecx
  115.             mov     [eax],ecx
  116.             mov     ecx, len
  117.             mov     edx, buffer
  118. #if defined(PRONTO_NAMESPACES)
  119.             call    @System@@LStrFromArray$qqrv
  120. #else
  121.             call    @@LStrFromArray$qqrv
  122. #endif
  123.         }
  124.         //!JK redo this routine, don't mess with the stack (with C++ in between)
  125.         asm     push    eax
  126.         delete[] buffer;
  127.         asm     pop     eax
  128.     }
  129. }
  130. //---------------------------------------------------------------------------
  131. __fastcall      AnsiString::AnsiString(char src)
  132. {
  133.   char s[2];
  134.   char* sptr = s;
  135.   s[0] = src;
  136.   s[1] = 0;
  137.   asm
  138.   {
  139. #if defined(PRONTO_NAMESPACES)
  140.     extrn   @System@@LStrFromPChar$qqrv:near
  141. #else
  142.     extrn   @@LStrFromPChar$qqrv:near
  143. #endif
  144.     xor     ecx,ecx
  145.     mov     eax, this
  146.     mov     [eax], ecx
  147.     mov     edx, sptr
  148. #if defined(PRONTO_NAMESPACES)
  149.     call    @System@@LStrFromPChar$qqrv
  150. #else
  151.     call    @@LStrFromPChar$qqrv
  152. #endif
  153.   }
  154. }
  155. //---------------------------------------------------------------------------
  156. __fastcall AnsiString::AnsiString(int src)
  157. {
  158.   Data = 0;
  159. #if defined(PRONTO_NAMESPACES)
  160.   *this = Sysutils::IntToStr(src);
  161. #else
  162.   *this = ::IntToStr(src);
  163. #endif
  164. }
  165. //---------------------------------------------------------------------------
  166. __fastcall AnsiString::AnsiString(double src)
  167. {
  168.   Data = 0;
  169. #if defined(PRONTO_NAMESPACES)
  170.   *this = Sysutils::FloatToStr(src);
  171. #else
  172.   *this = ::FloatToStr(src);
  173. #endif
  174. }
  175. //---------------------------------------------------------------------------
  176. __fastcall      AnsiString::~AnsiString()
  177. {
  178.     asm
  179.     {
  180. #if defined(PRONTO_NAMESPACES)
  181.         extrn   @System@@LStrClr$qqrv:near
  182. #else
  183.         extrn   @@LStrClr$qqrv:near
  184. #endif
  185.         //!JK don't even think of removing the mov eax, this line
  186.         //!JK apparently, the this ptr is not in eax on destructors
  187.         mov     eax,this
  188. #if defined(PRONTO_NAMESPACES)
  189.         call    @System@@LStrClr$qqrv
  190. #else
  191.         call    @@LStrClr$qqrv
  192. #endif
  193.     }
  194. }
  195. //---------------------------------------------------------------------------
  196. AnsiString& __fastcall AnsiString::operator=(const AnsiString&)
  197. {
  198.     asm
  199.     {
  200. #if defined(PRONTO_NAMESPACES)
  201.         extrn   @System@@LStrAsg$qqrv:near
  202. #else
  203.         extrn   @@LStrAsg$qqrv:near
  204. #endif
  205.         mov     edx,[edx]
  206. #if defined(PRONTO_NAMESPACES)
  207.         call    @System@@LStrAsg$qqrv
  208. #else
  209.         call    @@LStrAsg$qqrv
  210. #endif
  211.     }
  212.     return *this;
  213. }
  214. //---------------------------------------------------------------------------
  215. AnsiString& __fastcall AnsiString::operator+=(const AnsiString&)
  216. {
  217.     asm
  218.     {
  219. #if defined(PRONTO_NAMESPACES)
  220.         extrn   @System@@LStrCat$qqrv:near
  221. #else
  222.         extrn   @@LStrCat$qqrv:near
  223. #endif
  224.         mov     edx,[edx]
  225. #if defined(PRONTO_NAMESPACES)
  226.         call    @System@@LStrCat$qqrv
  227. #else
  228.         call    @@LStrCat$qqrv
  229. #endif
  230.     }
  231.     return *this;
  232. }
  233. //---------------------------------------------------------------------------
  234. AnsiString __fastcall AnsiString::operator+(const AnsiString& rhs) const
  235. {
  236.     //!JK Per Peter S., change to push 0 onto the stack
  237.     //!JK and use as the first parm
  238.     //!JK need to take out double contruction (return tmp)
  239.     AnsiString tmp;
  240.     AnsiString* ptmp = &tmp;
  241.     asm
  242.     {
  243. #if defined(PRONTO_NAMESPACES)
  244.         extrn   @System@@LStrCat3$qqrv:near
  245. #else
  246.         extrn   @@LStrCat3$qqrv:near
  247. #endif
  248.         mov     edx, this
  249.         mov     edx, [edx]
  250.         mov     eax, ptmp
  251.         mov     ecx, rhs
  252.         mov     ecx, [ecx]
  253. #if defined(PRONTO_NAMESPACES)
  254.         call    @System@@LStrCat3$qqrv
  255. #else
  256.         call    @@LStrCat3$qqrv
  257. #endif
  258.     }
  259.     return tmp;
  260. }
  261. //---------------------------------------------------------------------------
  262. bool __fastcall AnsiString::operator==(const AnsiString&) const
  263. {
  264.     asm
  265.     {
  266. #if defined(PRONTO_NAMESPACES)
  267.         extrn   @System@@LStrCmp$qqrv:near
  268. #else
  269.         extrn   @@LStrCmp$qqrv:near
  270. #endif
  271.         mov     eax, [eax]
  272.         mov     edx, [edx]
  273. #if defined(PRONTO_NAMESPACES)
  274.         call    @System@@LStrCmp$qqrv
  275. #else
  276.         call    @@LStrCmp$qqrv
  277. #endif
  278.         sete    al
  279.         and     eax, 1
  280.     }
  281. }
  282. //---------------------------------------------------------------------------
  283. bool __fastcall AnsiString::operator!=(const AnsiString&) const
  284. {
  285.     asm
  286.     {
  287. #if defined(PRONTO_NAMESPACES)
  288.         extrn   @System@@LStrCmp$qqrv:near
  289. #else
  290.         extrn   @@LStrCmp$qqrv:near
  291. #endif
  292.         mov     eax, [eax]
  293.         mov     edx, [edx]
  294. #if defined(PRONTO_NAMESPACES)
  295.         call    @System@@LStrCmp$qqrv
  296. #else
  297.         call    @@LStrCmp$qqrv
  298. #endif
  299.         setne   al
  300.         and     eax, 1
  301.     }
  302. }
  303. //---------------------------------------------------------------------------
  304. bool __fastcall AnsiString::operator<(const AnsiString&) const
  305. {
  306.     asm
  307.     {
  308. #if defined(PRONTO_NAMESPACES)
  309.         extrn   @System@@LStrCmp$qqrv:near
  310. #else
  311.         extrn   @@LStrCmp$qqrv:near
  312. #endif
  313.         mov     eax, [eax]
  314.         mov     edx, [edx]
  315. #if defined(PRONTO_NAMESPACES)
  316.         call    @System@@LStrCmp$qqrv
  317. #else
  318.         call    @@LStrCmp$qqrv
  319. #endif
  320.         setb    al
  321.         and     eax, 1
  322.     }
  323. }
  324. //---------------------------------------------------------------------------
  325. bool __fastcall AnsiString::operator>(const AnsiString&) const
  326. {
  327.     asm
  328.     {
  329. #if defined(PRONTO_NAMESPACES)
  330.         extrn   @System@@LStrCmp$qqrv:near
  331. #else
  332.         extrn   @@LStrCmp$qqrv:near
  333. #endif
  334.         mov     eax, [eax]
  335.         mov     edx, [edx]
  336. #if defined(PRONTO_NAMESPACES)
  337.         call    @System@@LStrCmp$qqrv
  338. #else
  339.         call    @@LStrCmp$qqrv
  340. #endif
  341.         seta    al
  342.         and     eax, 1
  343.     }
  344. }
  345. //---------------------------------------------------------------------------
  346. bool __fastcall AnsiString::operator<=(const AnsiString& rhs) const
  347. {
  348.     return !operator>(rhs);
  349. }
  350.  
  351. //---------------------------------------------------------------------------
  352. bool __fastcall AnsiString::operator >=(const AnsiString& rhs) const
  353. {
  354.     return !operator<(rhs);
  355. }
  356. //---------------------------------------------------------------------------
  357. int __fastcall AnsiString::AnsiCompare(const AnsiString& rhs) const
  358. {
  359. #if defined(PRONTO_NAMESPACES)
  360.   return Sysutils::AnsiCompareStr(*this, rhs);
  361. #else
  362.   return ::AnsiCompareStr(*this, rhs);
  363. #endif
  364. }
  365. //---------------------------------------------------------------------------
  366. int __fastcall AnsiString::AnsiCompareIC(const AnsiString& rhs) const
  367. {
  368. #if defined(PRONTO_NAMESPACES)
  369.   return Sysutils::AnsiCompareText(*this, rhs);
  370. #else
  371.   return ::AnsiCompareText(*this, rhs);
  372. #endif
  373. }
  374. //---------------------------------------------------------------------------
  375. int __fastcall AnsiString::Length() const
  376. {
  377.     asm
  378.     {
  379. #if defined(PRONTO_NAMESPACES)
  380.         extrn   @System@@LStrLen$qqrv:near
  381. #else
  382.         extrn   @@LStrLen$qqrv:near
  383. #endif
  384.         mov     eax, [eax]
  385. #if defined(PRONTO_NAMESPACES)
  386.         call    @System@@LStrLen$qqrv
  387. #else
  388.         call    @@LStrLen$qqrv
  389. #endif
  390.     }
  391. }
  392. //---------------------------------------------------------------------------
  393. bool __fastcall AnsiString::IsEmpty() const
  394. {
  395.     asm
  396.     {
  397.         mov     eax, [eax]
  398.         test    eax, eax
  399.         sete    al
  400.         and     eax, 1
  401.     }
  402. }
  403. //---------------------------------------------------------------------------
  404. // Return AnsiString of count chars of value ch
  405. AnsiString __fastcall AnsiString::StringOfChar(char ch, int count)
  406. {
  407.   char* s = new char[count+1];
  408.   for (int i = 0; i < count; i++)
  409.     s[i] = ch;
  410.   s[count] = 0;
  411.   AnsiString tmp(s);
  412.   delete [] s;
  413.   return tmp;
  414. }
  415. //---------------------------------------------------------------------------
  416. AnsiString __fastcall AnsiString::LoadStr(int ident)
  417. {
  418. #if defined(PRONTO_NAMESPACES)
  419.   return Sysutils::LoadStr(ident);
  420. #else
  421.   return ::LoadStr(ident);
  422. #endif
  423. }
  424. //---------------------------------------------------------------------------
  425. AnsiString __fastcall AnsiString::FmtLoadStr(int ident, const TVarRec* args,
  426.   int size)
  427. {
  428. #if defined(PRONTO_NAMESPACES)
  429.   return Sysutils::FmtLoadStr(ident, args, size);
  430. #else
  431.   return ::FmtLoadStr(ident, args, size);
  432. #endif
  433. }
  434. //---------------------------------------------------------------------------
  435. AnsiString __fastcall AnsiString::Format(const AnsiString& format,
  436.   const TVarRec *args, int size)
  437. {
  438. #if defined(PRONTO_NAMESPACES)
  439.   return Sysutils::Format(format, args, size);
  440. #else
  441.   return ::Format(format, args, size);
  442. #endif
  443. }
  444. //---------------------------------------------------------------------------
  445. AnsiString __fastcall AnsiString::FormatFloat(const AnsiString& format,
  446.   const long double& value)
  447. {
  448. #if defined(PRONTO_NAMESPACES)
  449.   return Sysutils::FormatFloat(format, value);
  450. #else
  451.   return ::FormatFloat(format, value);
  452. #endif
  453. }
  454. //---------------------------------------------------------------------------
  455. AnsiString __fastcall AnsiString::FloatToStrF(long double value,
  456.       TStringFloatFormat format, int precision, int digits)
  457. {
  458.   //!JK this code requires TStringFloatFormat and TFloatFormat to be identical
  459. #if defined(PRONTO_NAMESPACES)
  460.   return Sysutils::FloatToStrF(value, TFloatFormat(format), precision, digits);
  461. #else
  462.   return ::FloatToStrF(value, TFloatFormat(format), precision, digits);
  463. #endif
  464. }
  465. //---------------------------------------------------------------------------
  466. AnsiString __fastcall AnsiString::IntToHex(int value, int digits)
  467. {
  468. #if defined(PRONTO_NAMESPACES)
  469.   return Sysutils::IntToHex(value, digits);
  470. #else
  471.   return ::IntToHex(value, digits);
  472. #endif
  473. }
  474. //---------------------------------------------------------------------------
  475. AnsiString __fastcall AnsiString::CurrToStr(Currency value)
  476. {
  477. #if !defined(PRONTO_NAMESPACES)
  478.   return ::CurrToStr(value);
  479. #else
  480.   return Sysutils::CurrToStr(value);
  481. #endif
  482. }
  483. //---------------------------------------------------------------------------
  484. AnsiString __fastcall AnsiString::CurrToStrF(Currency value,
  485.       TStringFloatFormat format, int digits)
  486. {
  487.   //!JK this code requires TStringFloatFormat and TFloatFormat to be identical
  488. #if !defined(PRONTO_NAMESPACES)
  489.   return ::CurrToStrF(value, TFloatFormat(format), digits);
  490. #else
  491.   return Sysutils::CurrToStrF(value, TFloatFormat(format), digits);
  492. #endif
  493. }
  494. //---------------------------------------------------------------------------
  495. int __fastcall AnsiString::WideCharBufSize() const
  496. {
  497.   // return size of buffer required to call WideChar()
  498.   return MultiByteToWideChar(CP_ACP,0,(Data)? Data: (const PChar)"", -1, 0,0);
  499. }
  500. //---------------------------------------------------------------------------
  501. //Convert to Unicode
  502. wchar_t* __fastcall AnsiString::WideChar(wchar_t* dest, int destSize) const
  503. {
  504.   MultiByteToWideChar(CP_ACP,0,(Data)?Data: (const PChar)"",-1,dest,destSize);
  505.   return dest;
  506. }
  507. //---------------------------------------------------------------------------
  508. void __fastcall AnsiString::Unique()
  509. {
  510. #if defined(PRONTO_NAMESPACES)
  511.   System::UniqueString(*this);
  512. #else
  513.   ::UniqueString(*this);
  514. #endif
  515. }
  516. //---------------------------------------------------------------------------
  517. void __fastcall AnsiString::Insert(const String& source, int index)
  518. {
  519.   asm
  520.   {
  521. #if defined(PRONTO_NAMESPACES)
  522.     extrn   @System@@LStrInsert$qqrv:near
  523. #else
  524.     extrn   @@LStrInsert$qqrv:near
  525. #endif
  526.     //!JK edx must be a pointer to the characters
  527.     mov     edx, this
  528.     //!JK eax must be the characters themselves!
  529.     mov     eax, source
  530.     mov     eax, [eax]
  531.     mov     ecx, index
  532. #if defined(PRONTO_NAMESPACES)
  533.     call    @System@@LStrInsert$qqrv
  534. #else
  535.     call    @@LStrInsert$qqrv
  536. #endif
  537.   }
  538. }
  539. //---------------------------------------------------------------------------
  540. void __fastcall AnsiString::Delete(int index, int count)
  541. {
  542.   asm
  543.   {
  544. #if defined(PRONTO_NAMESPACES)
  545.     extrn   @System@@LStrDelete$qqrv:near
  546. #else
  547.     extrn   @@LStrDelete$qqrv:near
  548. #endif
  549.     //!JK eax must be a pointer to the characters
  550.     mov     eax, this
  551.     mov     edx, index
  552.     mov     ecx, count
  553. #if defined(PRONTO_NAMESPACES)
  554.     call    @System@@LStrDelete$qqrv
  555. #else
  556.     call    @@LStrDelete$qqrv
  557. #endif
  558.   }
  559. }
  560. //---------------------------------------------------------------------------
  561. void __fastcall AnsiString::SetLength(int newLength)
  562. {
  563.   asm
  564.   {
  565. #if defined(PRONTO_NAMESPACES)
  566.     extrn   @System@@LStrSetLength$qqrv:near
  567. #else
  568.     extrn   @@LStrSetLength$qqrv:near
  569. #endif
  570.     //!JK  eax must be a pointer to the characters
  571.     mov     eax, this
  572.     mov     edx, newLength
  573. #if defined(PRONTO_NAMESPACES)
  574.     call    @System@@LStrSetLength$qqrv
  575. #else
  576.     call    @@LStrSetLength$qqrv
  577. #endif
  578.   }
  579. }
  580. //---------------------------------------------------------------------------
  581. int __fastcall AnsiString::Pos(const AnsiString& subStr) const
  582. {
  583.   asm
  584.   {
  585. #if defined(PRONTO_NAMESPACES)
  586.     extrn   @System@@LStrPos$qqrv:near
  587. #else
  588.     extrn   @@LStrPos$qqrv:near
  589. #endif
  590.     //!JK edx must be the characters themselves!
  591.     mov     edx, this
  592.     mov     edx, [edx]
  593.     //!JK eax must be the characters themselves!
  594.     mov     eax, subStr
  595.     mov     eax, [eax]
  596. #if defined(PRONTO_NAMESPACES)
  597.     call    @System@@LStrPos$qqrv
  598. #else
  599.     call    @@LStrPos$qqrv
  600. #endif
  601.   //Result left in eax
  602.   }
  603. }
  604. //---------------------------------------------------------------------------
  605. AnsiString __fastcall AnsiString::LowerCase() const
  606. {
  607. #if defined(PRONTO_NAMESPACES)
  608.   return Sysutils::AnsiLowerCase(*this);
  609. #else
  610.   return ::AnsiLowerCase(*this);
  611. #endif
  612. }
  613. //---------------------------------------------------------------------------
  614. AnsiString __fastcall AnsiString::UpperCase() const
  615. {
  616. #if defined(PRONTO_NAMESPACES)
  617.   return Sysutils::AnsiUpperCase(*this);
  618. #else
  619.   return ::AnsiUpperCase(*this);
  620. #endif
  621. }
  622. //---------------------------------------------------------------------------
  623. AnsiString __fastcall AnsiString::Trim() const
  624. {
  625. #if defined(PRONTO_NAMESPACES)
  626.   return Sysutils::Trim(*this);
  627. #else
  628.   return ::Trim(*this);
  629. #endif
  630. }
  631. //---------------------------------------------------------------------------
  632. AnsiString __fastcall AnsiString::TrimLeft() const
  633. {
  634. #if defined(PRONTO_NAMESPACES)
  635.   return Sysutils::TrimLeft(*this);
  636. #else
  637.   return ::TrimLeft(*this);
  638. #endif
  639. }
  640. //---------------------------------------------------------------------------
  641. AnsiString __fastcall AnsiString::TrimRight() const
  642. {
  643. #if defined(PRONTO_NAMESPACES)
  644.   return Sysutils::TrimRight(*this);
  645. #else
  646.   return ::TrimRight(*this);
  647. #endif
  648. }
  649. //---------------------------------------------------------------------------
  650. AnsiString __fastcall AnsiString::SubString(int index, int count) const
  651. {
  652.   AnsiString tmp;
  653.   AnsiString* ptmp = &tmp;
  654.   asm
  655.   {
  656. #if defined(PRONTO_NAMESPACES)
  657.     extrn   @System@@LStrCopy$qqrv:near
  658. #else
  659.     extrn   @@LStrCopy$qqrv:near
  660. #endif
  661.     //!JK  eax must be a pointer to the characters
  662.     mov     eax, ptmp
  663.     push    eax
  664.     mov     ecx, count
  665.     mov     edx, index
  666.     //!JK  eax must be the characters themselves
  667.     mov     eax, this
  668.     mov     eax, [eax]
  669. #if defined(PRONTO_NAMESPACES)
  670.     call    @System@@LStrCopy$qqrv
  671. #else
  672.     call    @@LStrCopy$qqrv
  673. #endif
  674.   }
  675.   return tmp;
  676. }
  677. //---------------------------------------------------------------------------
  678. int __fastcall AnsiString::ToInt() const
  679. {
  680. #if defined(PRONTO_NAMESPACES)
  681.   return Sysutils::StrToInt(*this);
  682. #else
  683.   return ::StrToInt(*this);
  684. #endif
  685. }
  686. //---------------------------------------------------------------------------
  687. int __fastcall AnsiString::ToIntDef(int defaultValue) const
  688. {
  689. #if defined(PRONTO_NAMESPACES)
  690.   return Sysutils::StrToIntDef(*this, defaultValue);
  691. #else
  692.   return ::StrToIntDef(*this, defaultValue);
  693. #endif
  694. }
  695. //---------------------------------------------------------------------------
  696. double __fastcall AnsiString::ToDouble() const
  697. {
  698.   //!JK change this to return a long double when the compiler properly
  699.   //!JK promotes/demotes long doubles/doubles
  700. #if defined(PRONTO_NAMESPACES)
  701.   return Sysutils::StrToFloat(*this);
  702. #else
  703.   return ::StrToFloat(*this);
  704. #endif
  705. }
  706. #if defined(MBCS)
  707. //---------------------------------------------------------------------------
  708. bool __fastcall AnsiString::IsDelimiter(const AnsiString& delimiters, int index) const
  709. {
  710. #if defined(PRONTO_NAMESPACES)
  711.   return Sysutils::IsDelimiter(delimiters, *this, index);
  712. #else
  713.   return ::IsDelimiter(delimiters, *this, index);
  714. #endif
  715. }
  716. //---------------------------------------------------------------------------
  717. int __fastcall AnsiString::AnsiPos(const AnsiString& subStr) const
  718. {
  719. #if defined(PRONTO_NAMESPACES)
  720.   return Sysutils::AnsiPos(subStr, *this);
  721. #else
  722.   return ::AnsiPos(subStr, *this);
  723. #endif
  724. }
  725. //---------------------------------------------------------------------------
  726. bool __fastcall AnsiString::IsPathDelimiter(int index) const
  727. {
  728. #if defined(PRONTO_NAMESPACES)
  729.   return Sysutils::IsPathDelimiter(*this, index);
  730. #else
  731.   return ::IsPathDelimiter(*this, index);
  732. #endif
  733. }
  734. //---------------------------------------------------------------------------
  735. int __fastcall AnsiString::LastDelimiter(const AnsiString& delimiters) const
  736. {
  737. #if defined(PRONTO_NAMESPACES)
  738.   return Sysutils::LastDelimiter(delimiters, *this);
  739. #else
  740.   return ::LastDelimiter(delimiters, *this);
  741. #endif
  742. }
  743. //---------------------------------------------------------------------------
  744. AnsiString::TStringMbcsByteType __fastcall AnsiString::ByteType(int index) const
  745. {
  746.   //!GCD this code requires TStringMbcsByteType and TMbcsByteType to be identical
  747. #if defined(PRONTO_NAMESPACES)
  748.   return TStringMbcsByteType(Sysutils::ByteType(*this, index));
  749. #else
  750.   return TStringMbcsByteType(::ByteType(*this, index));
  751. #endif
  752. }
  753. //---------------------------------------------------------------------------
  754. bool __fastcall AnsiString::IsLeadByte(int index) const
  755. {
  756.   return ByteType(index) == mbLeadByte;
  757. }
  758. //---------------------------------------------------------------------------
  759. bool __fastcall AnsiString::IsTrailByte(int index) const
  760. {
  761.   return ByteType(index) == mbTrailByte;
  762. }
  763. //---------------------------------------------------------------------------
  764. char* __fastcall AnsiString::AnsiLastChar() const
  765. {
  766. #if defined(PRONTO_NAMESPACES)
  767.   return Sysutils::AnsiLastChar(*this);
  768. #else
  769.   return ::AnsiLastChar(*this);
  770. #endif
  771. }
  772. #endif
  773. //---------------------------------------------------------------------------
  774. AnsiString __fastcall operator+(const char* lhs, const AnsiString& rhs)
  775. {
  776.   AnsiString tmp(lhs);
  777.   AnsiString* ptmp = &tmp;
  778.   asm
  779.   {
  780. #if defined(PRONTO_NAMESPACES)
  781.     extrn   @System@@LStrCat$qqrv:near
  782. #else
  783.     extrn   @@LStrCat$qqrv:near
  784. #endif
  785.     mov     eax,ptmp
  786.     mov     edx,rhs
  787.     mov     edx,[edx]
  788. #if defined(PRONTO_NAMESPACES)
  789.     call    @System@@LStrCat$qqrv
  790. #else
  791.     call    @@LStrCat$qqrv
  792. #endif
  793.   }
  794.   return tmp;
  795. }
  796. //---------------------------------------------------------------------------
  797. static void read_to_delim(istream& strm, char delim, AnsiString& str);
  798. istream& operator >>(istream& is, AnsiString& arg)
  799.   {read_to_delim(is, 0, arg);}
  800. //---------------------------------------------------------------------------
  801. static void read_to_delim(istream& strm, char delim, AnsiString& str)
  802. {
  803.     char ch;
  804.     int nchars = 0;
  805.     char array[4096];
  806.     int capacity = sizeof array;
  807.  
  808.     while ( 1 )
  809.         {
  810.  
  811.         // Read as many characters as we can, up to the delimitor:
  812.         strm.get( array+nchars, capacity-nchars+1, delim );
  813.  
  814.         // This is the new string length:
  815.         nchars += strlen( array+nchars );
  816.  
  817.         // What stopped us?  An EOF?
  818.         if( !strm.good() )
  819.             break;          // EOF encountered (or worse!)
  820.  
  821.         // Nope.  Was it the delimiter?
  822.         strm.get(ch);
  823.         if(ch==delim)
  824.             break;  // Yup. We're done.  Don't put it back on the stream.
  825.         else
  826.         strm.putback(ch);   // Nope, Put it back and keep going.
  827.  
  828.         }
  829.         str = array;
  830. }
  831. //---------------------------------------------------------------------------
  832. void __fastcall InitExe()
  833. {
  834.   asm
  835.   {
  836. #if defined(PRONTO_NAMESPACES)
  837.     extrn   @System@@InitExe$qqrv:near
  838.     call    @System@@InitExe$qqrv
  839. #else
  840.     extrn   @@InitExe$qqrv:near
  841.     call    @@InitExe$qqrv
  842. #endif
  843.   }
  844. }
  845. //---------------------------------------------------------------------
  846. #if defined(PRONTO_NAMESPACES)
  847. }
  848. #endif
  849.  
  850.  
  851. //---------------------------------------------------------------------
  852. //!BB The following is a hack that should be moved somewhere else - like
  853. //!BB the startup code. Currently it's not a problem since dstring.obj
  854. //!BB pulled in by the RTL/StartupCode anyway.
  855. //---------------------------------------------------------------------
  856. extern HINSTANCE _hInstance;
  857. extern char     __isDLL;
  858. extern char     __isGUI;
  859. void InitVCL()
  860. {
  861.   VclInit(__isDLL, long(_hInstance), __isGUI);
  862. }
  863. #pragma startup InitVCL 0
  864.  
  865. void ExitVCL()
  866. {
  867.   VclExit();
  868. }
  869. #pragma exit ExitVCL 31
  870.  
  871.