/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2015 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
namespace GreenshotPlugin.Core
{
public static class StringExtensions
{
private const string RGBIV = "dlgjowejgogkklwj";
private const string KEY = "lsjvkwhvwujkagfauguwcsjgu2wueuff";
///
/// Format a string with the specified object
///
/// String with formatting, like {name}
/// Object used for the formatting
/// Formatted string
public static string FormatWith(this string format, object source)
{
return FormatWith(format, null, source);
}
///
/// Format the string "format" with the source
///
///
///
/// object with properties, if a property has the type IDictionary string,string it can used these parameters too
/// Formatted string
public static string FormatWith(this string format, IFormatProvider provider, object source)
{
if (format == null)
{
throw new ArgumentNullException("format");
}
IDictionary properties = new Dictionary();
foreach (var propertyInfo in source.GetType().GetProperties())
{
if (propertyInfo.CanRead && propertyInfo.CanWrite)
{
object value = propertyInfo.GetValue(source, null);
if (propertyInfo.PropertyType != typeof(IDictionary))
{
properties.Add(propertyInfo.Name, value);
}
else
{
IDictionary dictionary = (IDictionary)value;
foreach (var propertyKey in dictionary.Keys)
{
properties.Add(propertyKey, dictionary[propertyKey]);
}
}
}
}
Regex r = new Regex(@"(?\{)+(?[\w\.\[\]]+)(?:[^}]+)?(?\})+", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
List