From commits-return-5889-archive-asf-public=cust-asf.ponee.io@royale.apache.org Sun Sep 23 20:14:28 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 3AE69180658 for ; Sun, 23 Sep 2018 20:14:28 +0200 (CEST) Received: (qmail 37943 invoked by uid 500); 23 Sep 2018 18:14:27 -0000 Mailing-List: contact commits-help@royale.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@royale.apache.org Delivered-To: mailing list commits@royale.apache.org Received: (qmail 37933 invoked by uid 99); 23 Sep 2018 18:14:27 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Sep 2018 18:14:27 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 9C1FE82A43; Sun, 23 Sep 2018 18:14:26 +0000 (UTC) Date: Sun, 23 Sep 2018 18:14:26 +0000 To: "commits@royale.apache.org" Subject: [royale-asjs] branch develop updated: Base64 encoding / decoding that works in all browsers even in IE11, so better doesn't use atob/btoa js methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <153772646656.15487.3599514296545013312@gitbox.apache.org> From: carlosrovira@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: royale-asjs X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Oldrev: 113f6ea0cc3eebad292f7476b7432475022165d9 X-Git-Newrev: 8e2a5d3c78838e6696db01795f84e7d5bdfd04e0 X-Git-Rev: 8e2a5d3c78838e6696db01795f84e7d5bdfd04e0 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. carlosrovira pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git The following commit(s) were added to refs/heads/develop by this push: new 8e2a5d3 Base64 encoding / decoding that works in all browsers even in IE11, so better doesn't use atob/btoa js methods 8e2a5d3 is described below commit 8e2a5d3c78838e6696db01795f84e7d5bdfd04e0 Author: Carlos Rovira AuthorDate: Sun Sep 23 20:14:18 2018 +0200 Base64 encoding / decoding that works in all browsers even in IE11, so better doesn't use atob/btoa js methods --- .../projects/Core/src/main/royale/CoreClasses.as | 1 + .../org/apache/royale/utils/string/Base64.as | 173 +++++++++++++++++++++ 2 files changed, 174 insertions(+) diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as b/frameworks/projects/Core/src/main/royale/CoreClasses.as index ee50b15..0928389 100644 --- a/frameworks/projects/Core/src/main/royale/CoreClasses.as +++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as @@ -272,6 +272,7 @@ import org.apache.royale.events.ItemRemovedEvent; ItemRemovedEvent; import org.apache.royale.utils.array.rangeCheck; rangeCheck; + import org.apache.royale.utils.string.Base64; Base64; import org.apache.royale.utils.string.contains; contains; import org.apache.royale.utils.string.isWhitespace; isWhitespace; import org.apache.royale.utils.string.trim; trim; diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/Base64.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/Base64.as new file mode 100644 index 0000000..7729f94 --- /dev/null +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/Base64.as @@ -0,0 +1,173 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.royale.utils.string +{ + /** + * Base64 encoding/decoding that works cross browsers + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.4 + */ + public class Base64 + { + public static const _keyStr:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + + /** + * encode a string in base64 + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.4 + */ + public static function encode(e:String):String + { + var t:String = ""; + var n:int,r:int,i:int,s:int,o:int,u:int,a:int; + var f:int = 0; + e = _utf8_encode(e); + while(f < e.length) + { + n=e.charCodeAt(f++); + r=e.charCodeAt(f++); + i=e.charCodeAt(f++); + s=n>>2; + o=(n&3)<<4|r>>4; + u=(r&15)<<2|i>>6; + a=i&63; + if(isNaN(r)) + { + u=a=64 + }else if(isNaN(i)) + { + a=64 + } + t=t+_keyStr.charAt(s)+_keyStr.charAt(o)+_keyStr.charAt(u)+_keyStr.charAt(a); + } + return t; + } + + /** + * decode string from base64 + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.4 + */ + public static function decode(e:String):String + { + var t:String = ""; + var n:int,r:int,i:int; + var s:int,o:int,u:int,a:int; + var f:int = 0; + e = e.replace(/[^A-Za-z0-9+/=]/g,""); + while(f>4; + r=(o&15)<<4|u>>2; + i=(u&3)<<6|a; + t=t+String.fromCharCode(n); + if(u!=64) + { + t=t+String.fromCharCode(r); + } + if(a!=64) + { + t=t+String.fromCharCode(i); + } + } + t = _utf8_decode(t); + return t; + } + + /** + * encode utf8 string + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.4 + */ + public static function _utf8_encode(e:String):String + { + e = e.replace(/rn/g,"n"); + var t:String = ""; + for(var n:int=0;n127&&r<2048) + { + t+=String.fromCharCode(r>>6|192); + t+=String.fromCharCode(r&63|128); + } else + { + t+=String.fromCharCode(r>>12|224); + t+=String.fromCharCode(r>>6&63|128); + t+=String.fromCharCode(r&63|128); + } + } + return t; + } + + /** + * decode utf8 string + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.4 + */ + public static function _utf8_decode(e:String):String + { + var t:String = ""; + var n:int,r:int,c1:int; + var c2:int=0; + while(n < e.length) + { + r = e.charCodeAt(n); + if(r < 128) + { + t += String.fromCharCode(r);n++; + } else if(r>191 && r<224) + { + c2 = e.charCodeAt(n+1); + t += String.fromCharCode((r&31)<<6|c2&63); + n+=2; + } else + { + c2 = e.charCodeAt(n+1); + var c3:int = e.charCodeAt(n+2); + t += String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63); + n += 3; + } + } + return t; + } + } +} \ No newline at end of file