Modify

Opened 11 years ago

Closed 11 years ago

#2914 closed Bug (Rejected)

_StringProper - Diacratic Char issue

Reported by: mLipok Owned by:
Milestone: Component: Standard UDFs
Version: 3.3.13.19 Severity: None
Keywords: Cc:

Description

Here is repro script:

#include <string.au3>

ConsoleWrite(@CR)
ConsoleWrite('_StringProper:' & @CR)
ConsoleWrite(_StringProper('SOSNOWIEC') & @CR)
ConsoleWrite(_StringProper('Jastrzębie-Zdrój') & @CR)
ConsoleWrite(_StringProper('Wodzisław ŚLĄSKI') & @CR)

ConsoleWrite(@CR)
ConsoleWrite('_StringProper_My:' & @CR)
ConsoleWrite(_StringProper_My('SOSNOWIEC') & @CR)
ConsoleWrite(_StringProper_My('Jastrzębie-Zdrój') & @CR)
ConsoleWrite(_StringProper_My('Wodzisław ŚLĄSKI') & @CR)

ConsoleWrite(@CR)
ConsoleWrite('_StringProper_My_2:' & @CR)
ConsoleWrite(_StringProper_My_2('SOSNOWIEC') & @CR)
ConsoleWrite(_StringProper_My_2('Jastrzębie-Zdrój') & @CR)
ConsoleWrite(_StringProper_My_2('Wodzisław ŚLĄSKI') & @CR)

ConsoleWrite(@CR)


; modified _StringProper()
Func _StringProper_My($sString)
	Local $bCapNext = True, $sChr = "", $sReturn = ""
	For $i = 1 To StringLen($sString)
		$sChr = StringMid($sString, $i, 1)
		Select
			Case $bCapNext = True
				; added ąĄćĆęĘłŁńŃóÓśŚżŻźŹ
				If StringRegExp($sChr, '(?i)[a-zA-ZĂ€-ÿšœžŸąĄćĆęĘłŁńŃóÓśŚżŻźŹ]') Then
					$sChr = StringUpper($sChr)
					$bCapNext = False
				EndIf
				; added ąĄćĆęĘłŁńŃóÓśŚżŻźŹ
			Case Not StringRegExp($sChr, '(?i)[a-zA-ZĂ€-ÿšœžŸąĄćĆęĘłŁńŃóÓśŚżŻźŹ]')
				$bCapNext = True
			Case Else
				$sChr = StringLower($sChr)
		EndSelect
		$sReturn &= $sChr
	Next
	Return $sReturn
EndFunc   ;==>_StringProper_My


; modified _StringProper()
Func _StringProper_My_2($sString)
	Local $bCapNext = True, $sChr = "", $sReturn = ""
	For $i = 1 To StringLen($sString)
		$sChr = StringMid($sString, $i, 1)
		Select
			Case $bCapNext = True
				; added ąĄćĆęĘłŁńŃóÓśŚżŻźŹ
				; removed €
				If StringRegExp($sChr, '(?i)[a-zA-ZĂ-ÿšœžŸąĄćĆęĘłŁńŃóÓśŚżŻźŹ]') Then
					$sChr = StringUpper($sChr)
					$bCapNext = False
				EndIf
				; added ąĄćĆęĘłŁńŃóÓśŚżŻźŹ
				; removed €
			Case Not StringRegExp($sChr, '(?i)[a-zA-ZĂ-ÿšœžŸąĄćĆęĘłŁńŃóÓśŚżŻźŹ]')
				$bCapNext = True
			Case Else
				$sChr = StringLower($sChr)
		EndSelect
		$sReturn &= $sChr
	Next
	Return $sReturn
EndFunc   ;==>_StringProper_My_2

Results (correct are from _StringProper_My_2)

_StringProper:
Sosnowiec
JastrzęBie-ZdróJ
WodzisłAw ŚlĄSki

_StringProper_My:
SOSNOWIEC
Jastrzębie-Zdrój
Wodzisław ŚLĄSKI

_StringProper_My_2:
Sosnowiec
Jastrzębie-Zdrój
Wodzisław Śląski

Attachments (0)

Change History (3)

comment:1 by jchd18, 11 years ago

Too specific in that you don't handle enough of Unicode.

#include <string.au3>

_ConsoleWrite('_StringProper_My:' & @CR)
_ConsoleWrite(_StringProper_My('SOSNOWIEC МОСКВА-КАЗАНСКИЙ ВОКЗАЛ ПЖДП') & @CR)
_ConsoleWrite(_StringProper_My('Jastrzębie-Zdrój ặἷἭὪἢῶ') & @CR)
_ConsoleWrite(_StringProper_My('Wodzisław ŚLĄSKI grÖßEN') & @CR)

; Language-independant version
Func _StringProper_My($s)
	Return(Execute('"' & StringRegExpReplace($s, '(*UCP)(\b\pL)(\pL*)', """ & StringUpper('\1') & StringLower('\2') & """) & '"'))
EndFunc

; display UTF8 correctly in SciTE console
Func _ConsoleWrite($s)
	ConsoleWrite(BinaryToString(StringToBinary($s, 4), 1))
EndFunc

Execute() is frown upon by some in standard UDF.

comment:2 by mLipok, 11 years ago

excellent

comment:3 by guinness, 11 years ago

Resolution: Rejected
Status: newclosed

There are too many variables to include for a function such as this.

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.