home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWString / SLLocale.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  2.4 KB  |  84 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLLocale.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef SLLOCALE_H
  13. #include "SLLocale.h"
  14. #endif
  15.  
  16. #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
  17. #include <Script.h>
  18. #endif
  19.  
  20. #ifdef FW_BUILD_MAC
  21. #pragma segment Strings
  22. #endif
  23.  
  24. //========================================================================================
  25. // FW_MacScriptIsSingleByte
  26. //========================================================================================
  27.  
  28. #ifdef FW_BUILD_MAC
  29. static FW_Boolean FW_MacScriptIsSingleByte(short script)
  30. {
  31.     static short gCachedScriptCode = smRoman;
  32.     static long gCachedScriptIsSingleByte = true;
  33.     if (script != gCachedScriptCode)
  34.     {
  35.         gCachedScriptCode = script;
  36.         long flags = GetScriptVariable(script, smScriptFlags);
  37.         gCachedScriptIsSingleByte = (flags & (1L<<smsfSingByte))!=0;
  38.     }
  39.     return gCachedScriptIsSingleByte;
  40. }
  41. #endif
  42.  
  43. //========================================================================================
  44. // FW_LocaleIsSingleByte
  45. //========================================================================================
  46.  
  47. FW_Boolean FW_LocaleIsSingleByte(FW_Locale locale)
  48. {
  49. #ifdef FW_BUILD_MAC
  50.     return FW_MacScriptIsSingleByte(locale.fScriptCode);
  51. #elif defined FW_BUILD_WIN
  52.     return true;
  53.  
  54.     // Someday, the code will look something like this:
  55.     //CPINFO cpinfo;
  56.     //GetACP(locale, &cpinfo);
  57.     //return cpinfo.MaxCharSize == 1;
  58.     // If GetACP might be expensive, it might be worthwhile mimicking the above
  59.     // routine which caches the result of the last call.
  60. #endif
  61. }
  62.  
  63. //========================================================================================
  64. // FW_CharIsDoubleByte
  65. //========================================================================================
  66.  
  67. FW_Boolean FW_CharIsDoubleByte(const char* p, short offset, const FW_Locale& locale)
  68. {
  69.     FW_Boolean result = false;    // assume false, which will be the case for single-byte scripts
  70.  
  71. #ifdef FW_BUILD_MAC
  72.     if (!FW_LocaleIsSingleByte(locale))
  73.     {
  74.         Ptr textBuf = (Ptr) p;
  75.         short byteType = ::CharacterByteType(textBuf, offset, locale.fScriptCode);
  76.         if (byteType == smFirstByte)
  77.             result = true;
  78.     }
  79. #endif
  80.  
  81.     return result;
  82. }
  83.  
  84.