#FEATURE by cg
class: CharacterArray
added: #asStringWithBitsPerCharacterAtLeast:
--- a/CharacterArray.st Sun May 26 12:00:09 2019 +0200
+++ b/CharacterArray.st Sun May 26 12:49:21 2019 +0200
@@ -1132,6 +1132,7 @@
"
! !
+
!CharacterArray methodsFor:'Compatibility-ANSI'!
addLineDelimiters
@@ -3866,6 +3867,37 @@
"Modified (comment): / 13-03-2017 / 14:05:14 / cg"
!
+asStringWithBitsPerCharacterAtLeast:numRequiredBitsPerCharacter
+ "return the receiver in a representation which supports numRequiredBitsPerCharacter.
+ I.e. if required, convert to a Unicode16 or Unicode32 string"
+
+ numRequiredBitsPerCharacter > 8 ifTrue:[
+ numRequiredBitsPerCharacter > 16 ifTrue:[
+ ^ self asUnicode32String
+ ].
+ numRequiredBitsPerCharacter > self bitsPerCharacter ifTrue:[
+ ^ self asUnicode16String
+ ].
+ ].
+ ^ self
+
+ "
+ self assert:('abc' asStringWithBitsPerCharacterAtLeast:8) bitsPerCharacter == 8.
+ self assert:('abc' asStringWithBitsPerCharacterAtLeast:16) bitsPerCharacter == 16.
+ self assert:('abc' asStringWithBitsPerCharacterAtLeast:32) bitsPerCharacter == 32.
+
+ self assert:('abc' asUnicode16String asStringWithBitsPerCharacterAtLeast:8) bitsPerCharacter == 16.
+ self assert:('abc' asUnicode16String asStringWithBitsPerCharacterAtLeast:16) bitsPerCharacter == 16.
+ self assert:('abc' asUnicode16String asStringWithBitsPerCharacterAtLeast:32) bitsPerCharacter == 32.
+
+ self assert:('abc' asUnicode32String asStringWithBitsPerCharacterAtLeast:8) bitsPerCharacter == 32.
+ self assert:('abc' asUnicode32String asStringWithBitsPerCharacterAtLeast:16) bitsPerCharacter == 32.
+ self assert:('abc' asUnicode32String asStringWithBitsPerCharacterAtLeast:32) bitsPerCharacter == 32.
+ "
+
+ "Created: / 26-05-2019 / 12:47:07 / Claus Gittinger"
+!
+
asStringWithoutEmphasis
"return myself as a string without any emphasis"
"return myself - I am a string"