fun mapToStr(map: Map<out Any?, Any?>?): String? { if (map == null) return null val buf = StringBuilder() var first = true for (entry in map.entrySet()) { val key: Any = entry.getKey() val value: Any = entry.getValue() if (key !is String || value !is String) continue var encodedName: String? = null try { encodedName = URLEncoder.encode(key, "UTF-8") } catch (e: UnsupportedEncodingException) { Debug.logError(e, module) } var encodedValue: String? = null try { encodedValue = URLEncoder.encode(value, "UTF-8") } catch (e: UnsupportedEncodingException) { Debug.logError(e, module) } if (first) first = false else buf.append("|") buf.append(encodedName) buf.append("=") buf.append(encodedValue) } return buf.toString() }
Creates an encoded String from a Map of name/value pairs ( MUST BE STRINGS ! )