/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v1.6.0
src/oscript/CmdLineHelper.cs
67 строк
2 KB
Michael Rybakin
fix #1055: падение при отстуствующих параметрах
21 дек 2020, 14:41
21 дек 2020, 14:41
c7a32ca
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json; namespace oscript { class CmdLineHelper { private string[] _args; private int _index = -1; public CmdLineHelper(string[] args) { _args = args; } public string Next() { _index++; if (_index >= _args.Length) return null; return _args[_index]; } public string Current() { if (_index < 0 || _index >= _args.Length) return null; return _args[_index]; } public string[] Tail() { return _args.Skip(_index+1).ToArray(); } public CmdLineParam Parse(string param) { var paramValue = new CmdLineParam(); var equality = param.IndexOf('='); if (equality == -1) { paramValue.Name = param; } else { paramValue.Name = param.Substring(0, equality); if (param.Length > equality + 1) paramValue.Value = param.Substring(equality + 1); else paramValue.Value = string.Empty; } return paramValue; } } }