Dictionary : Case Sensitive

BASE64 is by default upper case… but that does not mean that it can only REPRESENT uppercase content… as a matter of fact it will represent exact bit level content… otherwise you could not use it on images without corrupting them.

In Base64, “a” means something different than “A”, but a Dictionary considers them the same. Base64 only appears to work in most cases because conflicts are not likely with longer keys.

Hex encode each byte in the key string
There are other issues with this though (like composed vs noncomposed characters)

That’s how my subclass does it (the one in MacOSLib).

Or the one I wrote 10 years ago that’s been on my page since … forever :slight_smile:

[quote=235415:@Dave S]because I needed the key of “abc” to not be the same as the key “ABC”

it is to map character “names” to the actual character in my PDF class.

add_to_charmap(&hc0,"À","À") add_to_charmap(&he0,"à","à") [/quote]
If the key is the one character; Asc(“À”) ?

Can you not simply hex encode the key? You’d get a different value per case.

I just confirmed that JSONItem will mess up when the Base64 encoding of two different keys are the same but for case. Try this code, for example:

  dim j as new JSONItem
  j.Value( "Man" ) = 1
  j.Value( "MaT" ) = 2

ToString will give you {"Man":2}

Any point in filing a Feedback on this?

Also, as expected, the new framework JSON handling doesn’t have a problem with this.

JSONItem_MTC, the drop-in replacement for JSONItem, handles it properly too.

I filed Feedback.

<https://xojo.com/issue/41846>

Einhugur’s Dictionary is case-sensitive (and optional multi-key).

[quote=235438:@Kem Tekinay]JSONItem_MTC, the drop-in replacement for JSONItem, handles it properly too.

I filed Feedback.

<https://xojo.com/issue/41846>[/quote]
Thx. I’ll get this fixed right away.

[quote=235415:@Dave S]because I needed the key of “abc” to not be the same as the key “ABC”

it is to map character “names” to the actual character in my PDF class.

add_to_charmap(&hc0,"&Agrave;","À") add_to_charmap(&he0,"&agrave;","à") [/quote]

I am confused now. In your original post, you say you want it to be insensitive.

The encodeBase64 will correctly discriminate between abc and ABC, if it is what you need. No need to climb the great wall of China.

But hey, if one loves complexity…

But the output itself has case information which isn’t unique. Here ABCD and ABCE have the same output except for the case of A, so it wouldn’t work as a Dictionary Key.

s = EncodeBase64("ABCD") //"QUJDRA==" s = EncodeBase64("ABCE") //"QUJDRa=="

Well. All that is well and good. If we really want to make sure, here is a bullet proof method :

[code]Function makeKey(Key as string) As String
If Key = “” Then Return Key

Dim Result As String

For i As Integer = 0 To Len(Key)
dim c as integer = Asc(Mid(Key,i,1))
Result = Result + str© + Mid(Key,i,1)
Next

Return result
End Function[/code]

ABC = 065A66B67C
abc = 097a98b99c