forked from OpportunityLiu/LrcParser
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a10a842
commit 588e3e7
Showing
10 changed files
with
174 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Opportunity.LrcParser.UnitTest/Opportunity.LrcParser.UnitTest.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
|
||
namespace Opportunity.LrcParser | ||
{ | ||
internal static class TimeSpanExtension | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static string ToString(this TimeSpan dateTime, string mFormat, string smSep, string sFormat) | ||
{ | ||
var t = dateTime.Ticks; | ||
var m = t / TICKS_PER_MINUTE; | ||
t -= m * TICKS_PER_MINUTE; | ||
var s = (double)t / TICKS_PER_SECOND; | ||
return m.ToString(mFormat) + smSep + s.ToString(sFormat); | ||
} | ||
|
||
public static string ToLrcString(this TimeSpan timeSpan) | ||
=> timeSpan.ToString("D2", ":", "00.00"); | ||
|
||
public static string ToLrcStringRaw(this TimeSpan timeSpan) | ||
=> timeSpan.ToString("D2", ":", "00.00######"); | ||
|
||
public static string ToLrcStringShort(this TimeSpan timeSpan) | ||
=> timeSpan.ToString("D2", ":", "00"); | ||
|
||
public static bool TryParseLrcString(string value, int start, int end, out TimeSpan result) | ||
{ | ||
var m = 0; | ||
var s = 0; | ||
var t = 0; | ||
|
||
var i = start; | ||
for (; i < end; i++) | ||
{ | ||
var v = value[i] - '0'; | ||
if (v >= 0 && v <= 9) | ||
m = m * 10 + v; | ||
else if (value[i] == ':') | ||
{ | ||
i++; | ||
break; | ||
} | ||
else if (char.IsWhiteSpace(value, i)) | ||
{ | ||
continue; | ||
} | ||
else | ||
{ | ||
goto ERROR; | ||
} | ||
} | ||
|
||
for (; i < end; i++) | ||
{ | ||
var v = value[i] - '0'; | ||
if (v >= 0 && v <= 9) | ||
s = s * 10 + v; | ||
else if (value[i] == '.') | ||
{ | ||
i++; | ||
break; | ||
} | ||
else if (char.IsWhiteSpace(value, i)) | ||
{ | ||
continue; | ||
} | ||
else | ||
{ | ||
goto ERROR; | ||
} | ||
} | ||
|
||
var weight = (int)(TICKS_PER_SECOND / 10); | ||
for (; i < end; i++) | ||
{ | ||
var v = value[i] - '0'; | ||
if (v >= 0 && v <= 9) | ||
{ | ||
t += weight * v; | ||
weight /= 10; | ||
} | ||
else if (char.IsWhiteSpace(value, i)) | ||
{ | ||
continue; | ||
} | ||
else | ||
{ | ||
goto ERROR; | ||
} | ||
} | ||
; | ||
result = new TimeSpan(t + TICKS_PER_SECOND * s + TICKS_PER_MINUTE * m); | ||
return true; | ||
|
||
ERROR: | ||
result = default; | ||
return false; | ||
} | ||
|
||
public const long TICKS_PER_MINUTE = TICKS_PER_SECOND * 60; | ||
public const long TICKS_PER_SECOND = TICKS_PER_MILLISECOND * 1000; | ||
public const long TICKS_PER_MILLISECOND = 10_000; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# LrcParser | ||
[![Build status](https://ci.appveyor.com/api/projects/status/7ne8mex2di844260?svg=true)](https://ci.appveyor.com/project/OpportunityLiu/lrcparser) | ||
[![NuGet](https://img.shields.io/nuget/v/Opportunity.LrcParser.svg)](https://www.nuget.org/packages/Opportunity.LrcParser/) | ||
An library for lrc files. | ||
### LrcParser mod by appleneko2001 | ||
An lyric file parser (.lrc parser) for C# project. | ||
This is modded version with slightly changes framework of working. | ||
for original ver. ====>> https://github.com/OpportunityLiu/LrcParser | ||
|
||
## Quick Start | ||
##### Changes: | ||
* Use TimeSpan type instead of DateTime on timestamp property | ||
* UnitTest slightly changed to support this library | ||
|
||
### Parse An `LRC` File | ||
##### Requirements: | ||
This modded library uses .Net Standard 2.0, so your project should targeting .Net Framework to 4.6.1 at least | ||
for more information about minimum requirement of standard: https://docs.microsoft.com/en-us/dotnet/standard/net-standard#net-implementation-support | ||
|
||
To parse `lrc` files, use `Lyrics.Parse(string)` method, overloads can be used for variants of `lrc` formats. | ||
|
||
### Stringify A `Lyrics` Instance | ||
|
||
To create `lrc` file with a `Lyrics<TLine>` instance, call its `ToString()` method, you can also use `ToString(LyricsFormat)` overload to specify format settings. | ||
Or if you really want to use more older framework version, you can try to rebuild this library and targeting to .Net Standard 1.1 (or create new library project and copy-paste all codes. UnitTest are optional component). |