Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some conversions #474

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ private int ConvertCall(OpCode src, NeoMethod to, List<MethodToken> methodTokens
{
ConvertPushNumber(1, src, to);
Convert1by1(VM.OpCode.SUBSTR, null, to);
Insert1(VM.OpCode.CONVERT, "", to, new byte[] { (byte)VM.Types.StackItemType.Integer });
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}
else if (src.tokenMethod == "System.String System.String::Substring(System.Int32)")
Expand Down
16 changes: 16 additions & 0 deletions src/Neo.SmartContract.Framework/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,40 @@ public static byte ToByte(this int source)
[OpCode(OpCode.CAT)]
public extern static byte[] Concat(this byte[] first, ByteString second);

[OpCode(OpCode.CAT)]
[OpCode(OpCode.CONVERT, StackItemType.ByteString)]
public extern static string Concat(this string first, string second);
erikzhang marked this conversation as resolved.
Show resolved Hide resolved

[NonemitWithConvert(ConvertMethod.HexToBytes)]
public extern static byte[] HexToBytes(this string hex, bool reverse = false);

[OpCode(OpCode.SUBSTR)]
public extern static byte[] Range(this byte[] source, int index, int count);

[OpCode(OpCode.SUBSTR)]
[OpCode(OpCode.CONVERT, StackItemType.ByteString)]
public extern static string Range(this string source, int index, int count);
erikzhang marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Returns byte[] with first 'count' elements from 'source'. Faults if count < 0
/// </summary>
[OpCode(OpCode.LEFT)]
public extern static byte[] Take(this byte[] source, int count);
erikzhang marked this conversation as resolved.
Show resolved Hide resolved

[OpCode(OpCode.LEFT)]
[OpCode(OpCode.CONVERT, StackItemType.ByteString)]
public extern static string Take(this string source, int count);

/// <summary>
/// Returns byte[] with last 'count' elements from 'source'. Faults if count < 0
/// </summary>
[OpCode(OpCode.RIGHT)]
public extern static byte[] Last(this byte[] source, int count);

[OpCode(OpCode.RIGHT)]
[OpCode(OpCode.CONVERT, StackItemType.ByteString)]
public extern static string Last(this string source, int count);

/// <summary>
/// Returns a reversed copy of parameter 'source'.
/// Example: [0a,0b,0c,0d,0e] -> [0e,0d,0c,0b,0a]
Expand Down