This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 98be294b365f6db09bc0caec30c0674181b83cd9
Author: Josh Tynjala <[email protected]>
AuthorDate: Wed Apr 24 14:46:23 2024 -0700

    CSS.g: add support for modern rgb()/rgba() function syntax that has 
whitespace instead of commas between values, and forward slash / before alpha
    
    Now supports both new and legacy syntax
    
    rgb(100%, 100%, 100%) /* legacy rgb() */
    rgb(100% 100% 100%) /* new rgb() */
    rgba(100%, 100%, 100%, 100%) /* legacy rgba() */
    rgba(100% 100% 100% / 100%) /* new rgba() */
---
 .../org/apache/royale/compiler/internal/css/CSS.g       |  6 +++---
 .../compiler/internal/css/CSSRgbColorPropertyValue.java |  4 ++--
 .../internal/css/CSSRgbaColorPropertyValue.java         | 17 +++++++++--------
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git 
a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g 
b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
index 4e872d06d..dc960f7c6 100644
--- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
+++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
@@ -673,7 +673,7 @@ MATRIX3D_VALUE :  'matrix3d('       ( WS* NUMBER WS* ) ','
                     ; 
 
 /** 
- * Matches an rgba definition - rgba(100%,100%,100%,100%)
+ * Matches an rgba definition - rgba(100%,100%,100%,100%) or rgba(100% 100% 
100% / 100%)
  */
 RGBA :         'rgba('         ( WS* NUMBER ( PERCENT | ) WS* ) ',' 
                                ( WS* NUMBER ( PERCENT | ) WS* ) ',' 
@@ -682,13 +682,13 @@ RGBA :    'rgba('         ( WS* NUMBER ( PERCENT | ) WS* 
) ','
                ')'
     |   'rgba('        ( WS* NUMBER ( PERCENT | ) WS* ) 
                                ( WS* NUMBER ( PERCENT | ) WS* ) 
-                               ( WS* NUMBER ( PERCENT | ) WS* )
+                               ( WS* NUMBER ( PERCENT | ) WS* ) '/'
                                ( WS* NUMBER ( PERCENT | ) WS* ) 
                ')'
     ; 
 
 /** 
- * Matches a rgb definition - rgb(100%,100%,100%)
+ * Matches a rgb definition - rgb(100%,100%,100%) or rgb(100% 100% 100%)
  */
 RGB :  'rgb('  ( WS* NUMBER ( PERCENT | ) WS* ) ',' 
                                ( WS* NUMBER ( PERCENT | ) WS* ) ',' 
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbColorPropertyValue.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbColorPropertyValue.java
index bdcf1b4d3..9a2d3721f 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbColorPropertyValue.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbColorPropertyValue.java
@@ -58,7 +58,7 @@ public class CSSRgbColorPropertyValue extends CSSPropertyValue
      * @return int value bit color.
      */
     protected static int getIntValue(String rgb)
-    {        
+    {
         rgb = rgb.substring(4, rgb.length() - 1);
 
         StringBuffer sb = new StringBuffer();
@@ -71,7 +71,7 @@ public class CSSRgbColorPropertyValue extends CSSPropertyValue
         }
         else
         {
-            // separated by whitespace is allowed instead of commas
+            // separated by whitespace is considered modern
             String[] elements = rgb.split("\\s+");
             iterator = Arrays.<Object>stream(elements).iterator();
         }
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbaColorPropertyValue.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbaColorPropertyValue.java
index aa2034c7f..2b4f969f7 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbaColorPropertyValue.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbaColorPropertyValue.java
@@ -54,11 +54,11 @@ public class CSSRgbaColorPropertyValue extends 
CSSPropertyValue
     /**
      * Computes from the given rgb definition a int value. 
      * 
-     * @param rgb definition - rgba(100, 0, 0)
+     * @param rgba definition - rgba(100, 0, 0)
      * @return int value bit color.
      */
     protected static long getIntValue(String rgb)
-    {        
+    {
         rgb = rgb.substring(5, rgb.length() - 1);
         
         StringBuffer sb = new StringBuffer();
@@ -71,10 +71,11 @@ public class CSSRgbaColorPropertyValue extends 
CSSPropertyValue
         }
         else
         {
-            // separated by whitespace is allowed instead of commas
-            String[] elements = rgb.split("\\s+");
+            // separated by whitespace (with / before alpha) is considered 
modern
+            String[] elements = rgb.split("(\\s*\\/\\s*)|(\\s+)");
             iterator = Arrays.<Object>stream(elements).iterator();
         }
+        int tokenIndex = 0;
         while (iterator.hasNext())
         {
             int digit;
@@ -89,22 +90,22 @@ public class CSSRgbaColorPropertyValue extends 
CSSPropertyValue
             }
             else
             {
-                if (iterator.hasNext())
+                if (tokenIndex < 3)
                 {
                     digit = Float.valueOf(t).intValue();
                     sb.append(Character.forDigit((digit >> 4) & 15, 16));
                     sb.append(Character.forDigit(digit & 15, 16));
                 }
-                else
+                else // alpha
                 {
-                    // alpha
                     Float alpha = Float.valueOf(t);
                     alpha *= 255;
                     digit = alpha.intValue();
                     sb.insert(0, Character.forDigit((digit >> 4) & 15, 16));
                     sb.insert(1, Character.forDigit(digit & 15, 16));
                 }
-            }            
+            }
+            tokenIndex++;       
         }
         return Long.parseLong( sb.substring(0, 8), 16 );
     }

Reply via email to