[css-values-4] String concatenation

We just had a discussion with Tab and fantasai in #css about adding string concatentation to CSS, either through a concat() function, or a plus (+) operator. Here’s a transcript, heavily edited for readability:

<leaverou> Quick question, according to the current state of the Values spec is attr() supposed to be used in url()? or is it not allowed there?
<fantasai> shouldn't be allowed there (makes no sense to allow it there)
<TabAtkins> ...depends. As of a few weeks ago, it's allowed, with the changes to Syntax we agreed on.
<leaverou> I know there’s a url type (I think), but I’m interested in the cases where you concatenate strings with an attribute value
<TabAtkins> You can't concat strings in CSS, though.
<fantasai> I don't think that was intended as a change
<leaverou> what about content: “foo” “bar”; then? Is that only for the content property?
<fantasai> that's only for the content property
<TabAtkins> fantasai: It falls out by virtue of making url() a function that takes a <string>.
<fantasai> string concatenation doesn't work, generally, in CSS
<leaverou> I see. Do you think it wouldn’t be useful?
<TabAtkins> Possibly, sure.
<fantasai> seems like it could be, for attr() and variables! but it's not a thing we have right now
<TabAtkins> Need some use-cases, is all. And one of the biggest ones wasn't possible until just recently (urls).
<leaverou> The one I had in mind right now (but pretty sure I’ve come across many more) is attr() values in data URIs. That would be super useful for SVG urlencoded data URIs, and not just attr() values, also variables, even counters
<TabAtkins> counter() is just a <string>, so sure.
<leaverou> Introducing a function for it would be awful though. Too many parens!
<TabAtkins> Gotta be like calc. I'd oppose adding new generic syntax to properties. :/ Sass has a concat function. Seems to be okay there.
<leaverou> Not sure why, as SASS accepts concatenation with +. I never had to use the concat function in SASS
<fantasai> we could probably do string concat with +, it's unambiguous cuz of quotes. Values L4 ? :)
<leaverou> Wouldn’t it require changes to the syntax spec too?
<fantasai> I don't think it would affect anything, unless Syntax for some reason chokes on plus signs. 2.1 looks like it handles it fine so it would in fact be a regression
<TabAtkins> No, Syntax has no problem. The only thing it does with + is combine it with a number if the next character is a digit. Otherwise it's just a delim. Syntax doesn't "choke" on anything. ^^_
»fantasai didn't think so
»fantasai thought that was an xplicit design goal

Thoughts?

~Lea

Received on Wednesday, 16 July 2014 17:50:44 UTC