You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.6 KiB
53 lines
1.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace uc
|
|
{
|
|
public static class StringExtention
|
|
{
|
|
static public int[] ConvertToPageRange(this string str)
|
|
{
|
|
HashSet<int> col = new HashSet<int>();
|
|
string[] ranges = str.Split(',');
|
|
foreach(var s in ranges)
|
|
{
|
|
int page;
|
|
if(int.TryParse(s, out page))
|
|
{
|
|
col.Add(page);
|
|
}
|
|
else
|
|
{
|
|
string[] pages = s.Split('-');
|
|
int start, end;
|
|
if(pages.Length == 2 && int.TryParse(pages[0], out start) && int.TryParse(pages[1], out end))
|
|
{
|
|
for(int i = start; i<= end; i++)
|
|
{
|
|
col.Add(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
int[] result = new int[col.Count];
|
|
col.CopyTo(result);
|
|
return result;
|
|
}
|
|
|
|
static public string GetRelativePath(this string targetPath, string refPath)
|
|
{
|
|
refPath = Path.GetFullPath(refPath + "/foo").Replace(@"\", @"/");
|
|
Uri baseUri = new Uri(refPath);
|
|
//Debug.Log("Base Path: " + baseUri);
|
|
|
|
targetPath = Path.GetFullPath(targetPath).Replace(@"\", @"/");
|
|
Uri targetUri = new Uri(targetPath );
|
|
//Debug.Log("Target Path: " + targetUri);
|
|
|
|
Uri relUri = baseUri.MakeRelativeUri(targetUri);
|
|
|
|
return relUri.ToString().Replace(@"/", @"\");
|
|
}
|
|
}
|
|
} |