-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #759 from apurvabanka/kotlin_string
Kotlin String Implementaiton
- Loading branch information
Showing
1 changed file
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
{ | ||
"meta": { | ||
"language": "kotlin", | ||
"language_version": "1.5", | ||
"language_name": "Kotlin", | ||
"structure": "strings" | ||
}, | ||
"concepts": { | ||
"is_primitive_or_not": { | ||
"name": "Is this a built-in type in this language?", | ||
"code": "Yes" | ||
}, | ||
"import": { | ||
"name": "Import the string class", | ||
"code": "import kotlin.String;", | ||
"comment": "Import is not necessary as 'String' is present by default in all Kotlin programs." | ||
}, | ||
"default_string_byte_encoding": { | ||
"name": "Default byte encoding (ex: ASCII, UTF-8, UTF-16, etc.)", | ||
"code": "UTF-8" | ||
}, | ||
"create_new_string": { | ||
"name": "Create new string", | ||
"code": "val myString: String = \"......\"" | ||
}, | ||
"create_multiline_string": { | ||
"name": "Create new multi-line string", | ||
"code": "val multiLineString = \"Line 1\n Line2\n Line3\";", | ||
"comment": "Multiline literal implementation does not exist in Kotlin." | ||
}, | ||
"assign_new_string": { | ||
"name": "Assign string from another string", | ||
"code": "val stringOne = \"A new string.\";\nval stringTwo = stringOne;" | ||
}, | ||
"destroy_string": { | ||
"name": "Destroy string", | ||
"not-implemented": true | ||
}, | ||
"length_of_string": { | ||
"name": "Length of string", | ||
"code": "variableName.length\n\"Word\".length" | ||
}, | ||
"max_length_of_string": { | ||
"name": "Maximum length of string", | ||
"code": "2,147,483,647 characters" | ||
}, | ||
"clear_string": { | ||
"name": "Clear/empty string", | ||
"code": "val stringVariableYouWantEmptied = \"\"\nval emptyString: String = String()" | ||
}, | ||
"is_empty": { | ||
"name": "Is string empty?", | ||
"code": "val results: Boolean = (stringVariable == null || \nstringVariable.length == 0)", | ||
"comment": "The results Boolean will return true if the string is null or is an empty string." | ||
}, | ||
"concatenate_two_strings": { | ||
"name": "Concatenate/join two strings", | ||
"code": "val str1 = \"Hello \"\n\"val str2 = \"World\"\nString str3 = str1 + str2" | ||
}, | ||
"concatenate_many_strings": { | ||
"name": "Concatenate/join many strings", | ||
"code": "val str1 = \"Hello \"\nval str2 = \"World\";\nval str3 = \"I\";\nval str4 = \"am\";\nval str5 = \"a computer!\";\nval results = str1 + str2 + str3 + str4 + str5;" | ||
}, | ||
"is_all_alphabetical": { | ||
"name": "Is string all alphabetical characters?", | ||
"code": "val isAllAlphabetical1 = str1.all { it.isLetter() }", | ||
"comment": "You can use isLetter to check if the string contains all alphabets" | ||
}, | ||
"is_all_numerical": { | ||
"name": "Is string all numerical characters?", | ||
"code": "val isAllNumerical1 = str1.all { it.isDigit() }", | ||
"comment": "You can use isDigit to check if the string contains all numbers" | ||
}, | ||
"is_all_alphanumeric": { | ||
"name": "Is string all alphanumeric characters?", | ||
"code": "val isAllAlphanumeric1 = str1.all { it.isLetterOrDigit() }", | ||
"comment": "You can use isLetterOrDigit to check if the string contains letters and alphabets" | ||
}, | ||
"is_decimal": { | ||
"name": "Is string a decimal number?", | ||
"not-implemented": true | ||
}, | ||
"is_all_whitespaces": { | ||
"name": "Is string all whitespace characters?", | ||
"code": "val isAllWhitespace1 = str1.all { it.isWhitespace() }", | ||
"comment": "You can use isWhitespace to check if the string contains all whitespaces" | ||
}, | ||
"is_all_uppercase": { | ||
"name": "Is string all uppercase characters?", | ||
"code": "input.all { it.isUpperCase() }", | ||
"comment": "isUpperCase is true if string is all uppercase." | ||
|
||
}, | ||
"is_all_lowercase": { | ||
"name": "Is string all lowercase characters?", | ||
"code": "val isAllLowercase = str.all { it.isLowerCase() }", | ||
"comment": "You can use isLowerCase to check if the string contains all whitespaces" | ||
}, | ||
"is_in_titlecase": { | ||
"name": "Is string formatted in title case?", | ||
"code": "val isTitleCase = str.split(\" \").all { it.isNotEmpty() && \n it[0].isUpperCase() && it.substring(1).all { char -> char.isLowerCase() } }" | ||
}, | ||
"does_substring_exist": { | ||
"name": "Does a substring exist in a string?", | ||
"code": "str.contains(subString)" | ||
}, | ||
"find_start_index_of_substring": { | ||
"name": "Find index of where a substring starts", | ||
"code": "str.indexOf(subString)" | ||
}, | ||
"find_start_index_of_additional_substring": { | ||
"name": "Find index of an additional substring (or starting at another index)", | ||
"code": "str.indexOf(subString, startIndex)" | ||
}, | ||
"find_start_index_of_substring_from_end": { | ||
"name": "Find substring index starting at end", | ||
"code": "str.lastIndexOf(subString, startIndex);" | ||
}, | ||
"count_occurrences_of_substring": { | ||
"name": "Find number of occurences of a substring", | ||
"not-implemented": true | ||
}, | ||
"get_leftmost_characters": { | ||
"name": "Get a specified number of characters from the left", | ||
"code": "inputString.take(n)", | ||
"comment": "Returns the left n characters" | ||
}, | ||
"get_rightmost_characters": { | ||
"name": "Get a specified number of characters from the right", | ||
"code": "inputString.takeLast(n)", | ||
"comment": "Returns the right n characters" | ||
}, | ||
"get_substring_from_start_and_end_index": { | ||
"name": "Return a substring from a string based on starting and ending indices", | ||
"code": "inputString.substring(startIndex, endIndex)" | ||
}, | ||
"get_substring_from_start_index_and_length": { | ||
"name": "Return a substring from a string based on starting index and size of substring", | ||
"code": "str.substring(startIndex, endIndex.length)", | ||
"comment": "Second parameter in substring() is exclusive." | ||
|
||
}, | ||
"convert_to_uppercase": { | ||
"name": "Convert string to all uppercase", | ||
"code": "str.toUppercase();" | ||
}, | ||
"convert_to_lowercase": { | ||
"name": "Convert string to all lowercase", | ||
"code": "str.toLowercase();" | ||
}, | ||
"convert_to_title_case": { | ||
"name": "Convert string to title case", | ||
"not-implemented": true | ||
}, | ||
"capitalize_string": { | ||
"name": "Capitalize first letter of a string", | ||
"code": "input[0].uppercaseChar() + input.substring(1)" | ||
}, | ||
"remove_whitespace": { | ||
"name": "Remove all whitespaces from string", | ||
"code": "input.replace(\"\\s+\".toRegex(), \"\")" | ||
}, | ||
"replace_substring": { | ||
"name": "Replace a substring with another string", | ||
"code": "replace(\"abcd\", \"dddd\")" | ||
}, | ||
"replace_all_substring": { | ||
"name": "Replace all substring matches with another string", | ||
"code": "input.replace(target, replacement)" | ||
}, | ||
"split_at_index": { | ||
"name": "Split string into a list of strings at a given index", | ||
"code": "input.substring(0, index) to input.substring(index)" | ||
}, | ||
"split_at_newlines": { | ||
"name": "Split string into a list of strings at every new line character", | ||
"code": "List stringList = strings.split(\"\\n\")" | ||
}, | ||
"split_at_substring": { | ||
"name": "Split string by locating all substrings", | ||
"code": "string.split(substring)" | ||
}, | ||
"merge_lists_into_string": { | ||
"name": "Merge a list of strings into one string", | ||
"code": "combinedList.joinToString(delimiter)" | ||
}, | ||
"encode_html_entities": { | ||
"name": "Encode HTML entities in a string (ex: ™ to ™)", | ||
"not-implemented": true | ||
}, | ||
"decode_html_entities": { | ||
"name": "Decode HTML entitles into characters", | ||
"not-implemented": true | ||
}, | ||
"encode_url_percent": { | ||
"name": "Encode URL percent encoding into string (ex: ' ' to %20)", | ||
"not-implemented": true | ||
}, | ||
"decode_url_percent": { | ||
"name": "Decode URL percent encoding", | ||
"not-implemented": true | ||
}, | ||
"encode_to_base64": { | ||
"name": "Encode string into Base64 format", | ||
"code": "Base64.getEncoder().encodeToString(input.toByteArray())" | ||
}, | ||
"decode_from_base64": { | ||
"name": "Decode string from Base64 format", | ||
"code": "val decodedBytes = Base64.getDecoder().decode(encodedString)\nreturn String(decodedBytes)" | ||
}, | ||
"format_string_function": { | ||
"name": "Function to format a string", | ||
"code": "String.format(template, *values)" | ||
}, | ||
"parameter_format_in_order": { | ||
"name": "Parameter used in format function if they're used in order", | ||
"not-implemented": true | ||
}, | ||
"format_as_integer": { | ||
"name": "Format parameter as an integer", | ||
"code": "input.toInt()" | ||
}, | ||
"format_number_in_scientific_notation_little_e": { | ||
"name": "Format number with scientific notation with 'e'", | ||
"code": "String.format(\"%.6e\", number).replace('E', 'e')" | ||
}, | ||
"format_number_in_octal": { | ||
"name": "Format number into octal", | ||
"code": "Integer.toOctalString(number)" | ||
}, | ||
"format_number_in_hexadecimal": { | ||
"name": "Format number into hexadecimal", | ||
"code": "Integer.toHexString(number)" | ||
} | ||
} | ||
} |