From 4331489799ca3e2e1a0dbbd295f138620f2b136e Mon Sep 17 00:00:00 2001 From: Jean-Pierre Ledure Date: Sat, 6 Dec 2025 16:58:23 +0100 Subject: [PATCH] ScriptForge case-sensitive keys in the Dictionary service Update of help file according https://gerrit.libreoffice.org/c/core/+/173044 Change-Id: If309899ce2c15d081d8085555ef473544d771ee6 Reviewed-on: https://gerrit.libreoffice.org/c/help/+/195187 Reviewed-by: Jean-Pierre Ledure Tested-by: Jenkins (cherry picked from commit 246631c6fdb13e9a018c96c72abfc002a07a7f8e) Reviewed-on: https://gerrit.libreoffice.org/c/help/+/195190 --- .../text/sbasic/shared/03/sf_dictionary.xhp | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/source/text/sbasic/shared/03/sf_dictionary.xhp b/source/text/sbasic/shared/03/sf_dictionary.xhp index 66ea38f8a4..bea803eb15 100644 --- a/source/text/sbasic/shared/03/sf_dictionary.xhp +++ b/source/text/sbasic/shared/03/sf_dictionary.xhp @@ -25,13 +25,13 @@ A dictionary is a collection of key-item pairs - The key is a case-insensitive string + The key is a string. In Basic scripts, the case sensitivity of the key is determined at Dictionary creation. In Python scripts, the key is always case-sensitive. Items may be of any type Keys and items can be retrieved, counted, updated, and much more. - The Dictionary service is similar to the built-in %PRODUCTNAME Basic Collection object, however with more features. For example, Collection objects do not support the retrieval of keys. Moreover, Dictionaries provide additional capabilities as replacing keys, testing if a specific key already exists and converting the Dictionary into an Array object or JSON string. + The Dictionary service is similar to the built-in %PRODUCTNAME Basic Collection object, however with more features. For example, Collection objects do not support the retrieval of keys. Moreover, Dictionaries provide additional capabilities as replacing keys, testing if a specific key already exists and converting the Dictionary into an array of PropertyValues or a JSON string.

Service invocation

@@ -39,8 +39,9 @@ GlobalScope.BasicLibraries.loadLibrary("ScriptForge") Dim myDict As Variant - myDict = CreateScriptService("Dictionary") - + myDict = CreateScriptService("Dictionary", True) + ' The keys are case-sensitive, hence the second argument is True + It is recommended to free resources after use: @@ -50,7 +51,7 @@ The example below creates an empty instance of the Dictionary service and uses the Python native update method to populate it with the contents of a Python dict object. dico = dict('A' = 1, 'B' = 2, 'C' = 3) - # Initialize myDict as an empty dict object + # Initialize myDict as an empty Dictionary object myDict = CreateScriptService('Dictionary') # Load the values of dico into myDict myDict.update(dico) @@ -67,7 +68,7 @@ print(myDict) # {'A': 1, 'B': 2, 'C': 3, 'D': 4} propval = myDict.ConvertToPropertyValues() - Because Python has built-in dictionary support, most of the methods in the Dictionary service are available for Basic scripts only. Exceptions are ConvertToPropertyValues and ImportFromPropertyValues that are supported in both Basic and Python. + Because Python has built-in dictionary support, most of the methods in the Dictionary service are available for Basic scripts only. Exceptions are the ConvertToPropertyValues and ImportFromPropertyValues methods that are supported in both Basic and Python.

Properties

@@ -191,7 +192,7 @@ dict.Add(key: str, item: any): bool - key: String value used to identify the Item. The key is not case-sensitive. + key: String value used to identify the Item. The case sensitivity of the key was determined at Dictionary creation.. item: Any value, including an array, a Basic object, a UNO object, a dictionary, etc. @@ -416,7 +417,7 @@ dict.Item(key: str): any - key: Not case-sensitive. If it does not exist, Empty value is returned. + key: If it does not exist, the Empty value is returned. The following example iterates over all keys in the dictionary and uses the Item method to access their values. @@ -444,7 +445,7 @@ dict.Remove(key: str): bool - key: Not case-sensitive. Must exist in the dictionary, otherwise an UNKNOWNKEYERROR error is raised. + key: Must exist in the dictionary, otherwise an UNKNOWNKEYERROR error is raised. myDict.Add("key1", 100) @@ -490,7 +491,7 @@ dict.ReplaceItem(key: str, value: any): bool - key: String value representing the key whose value will be replaced. Not case-sensitive. If the key does not exist in the dictionary, an UNKNOWNKEYERROR error is raised. + key: String value representing the key whose value will be replaced. If the key does not exist in the dictionary, an UNKNOWNKEYERROR error is raised. value: The new value of the item referred to with the key parameter. @@ -513,8 +514,8 @@ dict.ReplaceKey(key: str, value: str): bool - key: String value representing the key to be replaced. Not case-sensitive. If the key does not exist in the dictionary, a UNKNOWNKEYERROR error is raised. - value: String value for the new key. Not case-sensitive. If the new key already exists in the dictionary, an DUPLICATEKEYERROR error is raised. + key: String value representing the key to be replaced. If the key does not exist in the dictionary, a UNKNOWNKEYERROR error is raised. + value: String value for the new key. If the new key already exists in the dictionary, a DUPLICATEKEYERROR error is raised. myDict.Add("oldKey", 100)