W3C home > Mailing lists > Public > www-style@w3.org > September 2012

Re: [css3-fonts][cssom] proposal for revised definition of CSSFontFaceRule

From: Sebastian Zartner <sebastianzartner@gmail.com>
Date: Sat, 22 Sep 2012 00:35:36 +0200
Message-ID: <CAERejNaBksTC72n5ZgzOGbavvUQj_WrtxDgg9+WT5OvFHhYTFg@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: Glenn Adams <glenn@skynav.com>, Boris Zbarsky <bzbarsky@mit.edu>, John Daggett <jdaggett@mozilla.com>, www-style list <www-style@w3.org>
>
> > Ok. As long as there will be a mapping between them it's fine for me.
>
> Yeah, the mapping is trivial:
>
> function camelCaseFromDashes(str) {
>         str = str.toLowerCase();
>         var ret = '';
>         for(var i = 0; i < str.length; i++) {
>                 if(str[i] == '-' && i+1 < str.length) {
>                         ret += str[i+1].toUpperCase();
>                         i++;
>                 } else {
>                         ret += str[i];
>                 }
>         }
>         return ret;
> }
>
> function dashesFromCamelCase(str) {
>         var ret = '';
>         for(var i = 0; i < str.length; i++) {
>                 if(str[i].match(/[A-Z]/)) {
>                         ret += '-' + str[i].toLowerCase();
>                 } else {
>                         ret += str[i];
>                 }
>         }
>         return ret;
> }


This can even be reached easier:

function camelCaseFromDashes(str) {
  return str.replace(/-./g, function(m) { return m[1].toUpperCase(); });
}

function dashesFromCamelCase(str) {
  str.replace(/[A-Z]/g, function(m) { return "-"+m[0].toLowerCase(); });
}

Though I was not talking of a JavaScript mapping. I was talking of a
mapping in CSSOM as Glenn mentioned it. Imagine the camelCase notation
differs from the property name notation for some reason.

Sebastian
Received on Friday, 21 September 2012 22:36:04 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:21:00 GMT