public static SkryptObject Replace(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str         = self as StringInstance;
            var input       = arguments.GetAs <StringInstance>(0);
            var replacement = arguments.GetAs <StringInstance>(1);

            return(engine.CreateString(str.Value.Replace(input.Value, replacement.Value)));
        }
Example #2
0
        public static SkryptObject Read(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var destination = arguments.GetAs <StringInstance>(0);

            var str = engine.CreateString(engine.FileHandler.Read(destination));

            return(str);
        }
        public static SkryptObject Reverse(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str = self as StringInstance;

            char[] charArray = str.Value.ToCharArray();
            Array.Reverse(charArray);

            return(engine.CreateString(new string(charArray)));
        }
        public static SkryptObject ToArray(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str = self as StringInstance;

            var charArray = str.Value.ToCharArray();
            var array     = engine.CreateArray(new SkryptObject[0]);

            for (var i = 0; i < charArray.Length; i++)
            {
                ArrayInstance.Push(engine, array, new Arguments(engine.CreateString("" + charArray[i])));
            }

            return(array);
        }
        public static SkryptObject PadRight(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str        = (self as StringInstance).Value;
            var totalWidth = arguments.GetAs <NumberInstance>(0);
            var input      = arguments.GetAs <StringInstance>(1);
            var newStr     = "";

            while (newStr.Length < totalWidth)
            {
                newStr = newStr + input;
            }

            return(engine.CreateString(str + newStr));
        }
        public static SkryptObject Substring(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str   = self as StringInstance;
            var start = arguments.GetAs <NumberInstance>(0);
            var end   = arguments[1];

            if (end == null)
            {
                return(engine.CreateString(str.Value.Substring((int)start)));
            }
            else
            {
                if (end is NumberInstance)
                {
                    var length = Math.Max(Math.Min((int)(NumberInstance)end, str.Value.Length - 1) - (int)start, 0);

                    return(engine.CreateString(str.Value.Substring((int)start, length)));
                }
                else
                {
                    throw new InvalidArgumentTypeException($"Expected argument of type Number.");
                }
            }
        }
Example #7
0
        public static SkryptObject CallStack(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            int    i     = 0;
            int    count = engine.CallStack.Count();
            string str   = "";

            foreach (Call c in engine.CallStack)
            {
                var file = i == count - 1 ? c.callFile : c.file;
                file = file ?? c.callFile;

                str += $"\tat {c.name}() in {file} ({c.line},{c.column})\n";

                i++;
            }

            return(engine.CreateString(str));
        }
        public static SkryptObject FromByteArray(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var array     = arguments.GetAs <ArrayInstance>(0);
            var rawString = "";

            for (var i = 0; i < array.SequenceValues.Count; i++)
            {
                var rawValue = array.SequenceValues[i];

                if (rawValue is NumberInstance num)
                {
                    rawString += (char)num.Value;
                }
                else
                {
                    throw new FatalErrorException("Number expected.");
                }
            }

            return(engine.CreateString(rawString));
        }
        public static SkryptObject Split(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str   = self as StringInstance;
            var input = new List <string>();

            for (int i = 0; i < arguments.Values.Length; i++)
            {
                var s = arguments.GetAs <StringInstance>(i);

                input.Add(s.Value);
            }

            var split = str.Value.Split(input.ToArray(), StringSplitOptions.None);

            var stringArray = new StringInstance[split.Length];

            for (int i = 0; i < split.Length; i++)
            {
                stringArray[i] = engine.CreateString(split[i]);
            }

            return(engine.CreateArray(stringArray));
        }
        public static SkryptObject TrimEnd(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str = self as StringInstance;

            return(engine.CreateString(str.Value.TrimEnd()));
        }
 public ExceptionInstance(SkryptEngine engine, string message, string stackTrace) : base(engine)
 {
     CreateProperty("message", engine.CreateString(message), false, true);
     CreateProperty("stackTrace", engine.CreateString(stackTrace), false, true);
 }