It is currently Wed Sep 30, 2020 8:48 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Upper and Lower Case Error
PostPosted: Tue Aug 04, 2020 10:29 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2663
Location: Germany
The umlauts are not converted by macOS
Code:
a.s = "aou äöü àòù è áóú é @ ß € + *"
b.s = UCase(a)
c.s = LCase(b)

Debug a
Debug b
Debug c

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Upper and Lower Case Error
PostPosted: Tue Aug 04, 2020 10:31 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2663
Location: Germany
Workaround
Code:
;-TOP

; Comment : macOS Fix String Case
; Author  : mk-soft
; Version : v1.01.0
; Create  : 04.08.2020

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
 
  Structure _ArrayOfChar
    c.c[0]
  EndStructure
 
  Procedure.s FixLCase(String.s)
    Protected len, index, NewString.s, *NewString._ArrayOfChar
   
    NewString = String
    *NewString = @NewString
    If *NewString
      len = Len(NewString) - 1
     
      For index = 0 To len
        Select *NewString\c[index]
          Case 65 To 90
            *NewString\c[index] = *NewString\c[index] + 32
          Case 192 To 222
            If *NewString\c[index] = 208 Or *NewString\c[index] = 215
              ; Do Nothing
            Else
              *NewString\c[index] = *NewString\c[index] + 32
            EndIf
        EndSelect
      Next
    EndIf
    ProcedureReturn NewString
  EndProcedure
 
  Procedure.s FixUCase(String.s)
    Protected len, index, NewString.s, *NewString._ArrayOfChar
   
    NewString = String
    *NewString = @NewString
    If *NewString
      len = Len(NewString) - 1
      For index = 0 To len
        Select *NewString\c[index]
          Case 97 To 122
            *NewString\c[index] = *NewString\c[index] - 32
          Case 224 To 254
            If *NewString\c[index] = 240 Or *NewString\c[index] = 247
              ; Do Nothing
            Else
              *NewString\c[index] = *NewString\c[index] - 32
            EndIf
        EndSelect
      Next
    EndIf
    ProcedureReturn NewString
  EndProcedure
 
  Macro LCase(String)
    FixLCase(String)
  EndMacro
 
  Macro UCase(String)
    FixUCase(String)
  EndMacro
 
CompilerEndIf

; ****

CompilerIf #PB_Compiler_IsMainFile

  a.s = "abc-xyz äöü àòù è áóú é @ ß € + *"
  b.s = UCase(a)
  c.s = LCase(b)
 
  Debug a
  Debug b
  Debug c
 
CompilerEndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Tue Aug 04, 2020 11:14 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Upper and Lower Case Error
PostPosted: Tue Aug 04, 2020 11:05 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1763
Location: Germany
This is a long known bug which has already been posted by me in 2010 and by yourself in 2017...:wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: Upper and Lower Case Error
PostPosted: Tue Aug 04, 2020 12:31 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2663
Location: Germany
I think the method with Cocoa (base from wilbert) is better
Code:
;-TOP

; Comment : macOS Fix String Case (ThreadSafe)
; Author  : mk-soft
; Version : v2.01.0
; Create  : 04.08.2020

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
 
  Threaded _IsMainScope
  _IsMainScope = #True
 
  Procedure.s FixLCase(String.s, IsTread = #False)
    Protected Pool
    Protected NewString.s, Locale, NSString
   
    If Not _IsMainScope
      Pool = CocoaMessage(0, 0, "NSAutoreleasePool new")
    EndIf
   
    If String
      Locale = CocoaMessage(0, 0, "NSLocale currentLocale")
      NSString = CocoaMessage(0, 0, "NSString stringWithString:$", @String)
      NSString = CocoaMessage(0, NSString, "lowercaseStringWithLocale:", Locale)
      NewString = PeekS(CocoaMessage(0, NSString, "UTF8String"), -1, #PB_UTF8)
    EndIf
   
    If Pool
      CocoaMessage(0, Pool, "release")
    EndIf
    ProcedureReturn NewString
   
  EndProcedure
 
  Procedure.s FixUCase(String.s, IsTread = #False)
    Protected Pool
    Protected NewString.s, Locale, NSString
   
    If Not _IsThread
      Pool = CocoaMessage(0, 0, "NSAutoreleasePool new")
    EndIf
   
    If String
      Locale = CocoaMessage(0, 0, "NSLocale currentLocale")
      NSString = CocoaMessage(0, 0, "NSString stringWithString:$", @String)
      NSString = CocoaMessage(0, NSString, "uppercaseStringWithLocale:", Locale)
      NewString = PeekS(CocoaMessage(0, NSString, "UTF8String"), -1, #PB_UTF8)
    EndIf
   
    If Pool
      CocoaMessage(0, Pool, "release")
    EndIf
    ProcedureReturn NewString
   
  EndProcedure

  Macro LCase(String)
    FixLCase(String)
  EndMacro
 
  Macro UCase(String)
    FixUCase(String)
  EndMacro
 
CompilerEndIf

; ****

CompilerIf #PB_Compiler_IsMainFile
 
  Global a.s, b.s, c.s
 
  Procedure thWork(id)
    b = UCase(a)
    c = LCase(b)
    Debug a
    Debug b
    Debug c
  EndProcedure
 
  a = "abc-xyz äöü àòù è áóú é @ ß € + *"
  b = UCase(a)
  c = LCase(b)
 
  Debug a
  Debug b
  Debug c
 
  CreateThread(@thWork(), 0)
 
  Delay(1000)
 
CompilerEndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Upper and Lower Case Error
PostPosted: Tue Aug 04, 2020 12:44 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Dec 23, 2009 3:26 pm
Posts: 212
A bug that has been here for 10 years? :shock:

_________________
poor English...

PureBasic & Delphi & VBA


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye