camelcasing

Snippet regex: match arbitrary number of groups and transform to CamelCase

≯℡__Kan透↙ 提交于 2019-11-29 12:13:44
In a Visual Studio Code Snippet I'm writing I want to convert a snake case string to camel case. From the docs I know that the syntax is '${' var '/' regex '/' (format | text)+ '/' options '}' so I've come up with this : ${TM_FILENAME_BASE/([a-z])([a-z]*)_+([a-z])([a-z]*)_+/${1:/upcase}$2${3:/upcase}$4/} This code however works only for strings with 2 elements (for exemple "carrot_cake") while I would like to process strings with arbitrary number of elements ("blueberry_pie_with_a_cup_of_coffee"). I guess that some kind of recursion is needed in 'regex' and 'format' , but I have no idea of

Converting nested hash keys from CamelCase to snake_case in Ruby

情到浓时终转凉″ 提交于 2019-11-29 11:16:56
问题 I'm trying to build an API wrapper gem, and having issues with converting hash keys to a more Rubyish format from the JSON the API returns. The JSON contains multiple layers of nesting, both Hashes and Arrays. What I want to do is to recursively convert all keys to snake_case for easier use. Here's what I've got so far: def convert_hash_keys(value) return value if (not value.is_a?(Array) and not value.is_a?(Hash)) result = value.inject({}) do |new, (key, value)| new[to_snake_case(key.to_s).to

Default camel case of property names in JSON serialization

牧云@^-^@ 提交于 2019-11-28 23:54:42
问题 I have a bunch of classes that will be serialized to JSON at some point and for the sake of following both C# conventions on the back-end and JavaScript conventions on the front-end, I've been defining properties like this: [JsonProperty(PropertyName="myFoo")] public int MyFoo { get; set; } So that in C# I can: MyFoo = 10; And in Javascript I can: if (myFoo === 10) But doing this for every property is tedious. Is there a quick and easy way to set the default way JSON.Net handles property

Why True/False is capitalized in Python?

随声附和 提交于 2019-11-28 22:37:55
问题 All members are camel case, right? Why True/False but not true/false, which is more relaxed? 回答1: From Pep 285: Should the constants be called 'True' and 'False' (similar to None) or 'true' and 'false' (as in C++, Java and C99)? => True and False. Most reviewers agree that consistency within Python is more important than consistency with other languages. This, as Andrew points out, is probably because all (most)? built-in constants are capitalized. 回答2: All of python's built-in constants are

Naming convention for upper case abbreviations [closed]

核能气质少年 提交于 2019-11-28 22:26:42
Should a method that returns an XML stream be called public Stream getXmlStream(); or instead public Stream getXMLStream(); What's your opinion about that? What's considered best practice? There is no one correct answer. This wiki extract is helpful: Programming identifiers often need to contain acronyms and initialisms which are already in upper case, such as "old HTML file". By analogy with the title case rules, the natural camel case rendering would have the abbreviation all in upper case, namely "oldHTMLFile". However, this approach is problematic when two acronyms occur together (e.g.,

How to navigate through the source code by parts in CamelCase (instead of whole words)?

北战南征 提交于 2019-11-28 15:32:48
I remember when I was using Eclipse that when holding CTRL and using left or right arrows Eclipse would navigate over the LongCamelCaseWrittenWord in several steps. One camel case word at time. So it will go like follows (pipe | represents the actual cursor position): |LongCamelCaseWrittenWord -> CTRL+RIGHT_ARROW -> Long|CamelCaseWrittenWord -> CTRL+RIGHT_ARROW -> LongCamel|CaseWrittenWord -> CTRL+RIGHT_ARROW -> LongCamelCase|WrittenWord -> CTRL+RIGHT_ARROW -> LongCamelCaseWritten|Word -> CTRL+RIGHT_ARROW -> LongCamelCaseWrittenWord| Is there a way how to achieve this in IntelliJ? Currently

Snippet regex: match arbitrary number of groups and transform to CamelCase

让人想犯罪 __ 提交于 2019-11-28 01:47:36
问题 In a Visual Studio Code Snippet I'm writing I want to convert a snake case string to camel case. From the docs I know that the syntax is '${' var '/' regex '/' (format | text)+ '/' options '}' so I've come up with this : ${TM_FILENAME_BASE/([a-z])([a-z]*)_+([a-z])([a-z]*)_+/${1:/upcase}$2${3:/upcase}$4/} This code however works only for strings with 2 elements (for exemple "carrot_cake") while I would like to process strings with arbitrary number of elements ("blueberry_pie_with_a_cup_of

linux bash, camel case string to separate by dash

删除回忆录丶 提交于 2019-11-27 20:37:01
Is there a way to convert something like this: MyDirectoryFileLine to my-directory-file-line I found some ways to convert all letters to uppercase or lowercase, but not in that way; any ideas? dogbane You can use s/\([A-Z]\)/-\L\1/g to find an upper case letter and replace it with a dash and it's lower case. However, this gives you a dash at the beginning of the line, so you need another sed expression to handle that. This should work: sed --expression 's/\([A-Z]\)/-\L\1/g' \ --expression 's/^-//' \ <<< "MyDirectoryFileLine" 4ndrew I propose to use sed to do that: NEW=$(echo

Convert JSON style properties names to Java CamelCase names with GSON

痴心易碎 提交于 2019-11-27 17:16:33
I'm using GSON to convert JSON data I get to a Java object. It works pretty well in all my tests. The problem is that our real objects have some properties named like is_online. GSON only maps them if they are named totally equal, it would be nice to have GSON convert the names to Java camel case isOnline. It seems this is possible while creating the JSON data, camel case is converted to underscore separated words in JSON. But I can't find a way to specify this the other way round. I have found the following setting works perfect when reading json with underscored attributes and using

Convert hyphens to camel case (camelCase)

北城余情 提交于 2019-11-27 17:16:09
With regex (i assume) or some other method, how can i convert things like: marker-image or my-example-setting to markerImage or myExampleSetting . I was thinking about just splitting by - then convert the index of that hypen +1 to uppercase. But it seems pretty dirty and was hoping for some help with regex that could make the code cleaner. No jQuery... Try this: var camelCased = myString.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); }); The regular expression will match the -i in marker-image and capture only the i . This is then uppercased in the callback function and