Example #1
0
        public static int[] ToIntArray(Obj obj)
        {
            int len = obj.GetSize();

            int[] array = new int[len];
            for (int i = 0; i < len; i++)
            {
                array[i] = (int)obj.GetLongAt(i);
            }
            return(array);
        }
Example #2
0
        public static byte[] ToByteArray(Obj obj)
        {
            int len = obj.GetSize();

            byte[] array = new byte[len];
            for (int i = 0; i < len; i++)
            {
                array[i] = (byte)obj.GetLongAt(i);
            }
            return(array);
        }
Example #3
0
        private bool IsSyntacticSugaredString(TaggedObj tagObj)
        {
            Obj obj = tagObj.GetInnerObj();

            if (tagObj.GetTagId() != Cell.Runtime.SymbObj.StringSymbId | !obj.IsIntSeq())
            {
                return(false);
            }
            int len = obj.GetSize();

            for (int i = 0; i < len; i++)
            {
                if (!Miscellanea.IsBMPCodePoint(obj.GetLongAt(i)))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #4
0
        private void SyntacticSugaredString(Obj chars)
        {
            writer.Write('"');
            int len = chars.GetSize();

            for (int i = 0; i < len; i++)
            {
                int code = (char)chars.GetLongAt(i);
                if (code == '\n')
                {
                    writer.Write("\\n");
                }
                else if (code == '\t')
                {
                    writer.Write("\\t");
                }
                else if (code == '\\')
                {
                    writer.Write("\\\\");
                }
                else if (code == '"')
                {
                    writer.Write("\\\"");
                }
                else if (code >= 32 & code <= 126)
                {
                    writer.Write((char)code);
                }
                else
                {
                    writer.Write('\\');
                    for (int j = 0; j < 4; j++)
                    {
                        int  hexDigit = (code >> (12 - 4 * j)) % 16;
                        char ch       = (char)(hexDigit < 10 ? '0' + hexDigit : 'a' - 10 + hexDigit);
                        writer.Write(ch);
                    }
                }
            }
            writer.Write('"');
        }