@@ -15,13 +15,14 @@ struct char<N> {
1515 private byte[] bytes;
1616
1717 public char<N>(string s){
18- var buffer = System.Text.Encoding.ASCII.GetBytes(s);
19- this.size = buffer.Length;
2018 this.bytes=new byte[<N>];
21- if (size> <N>){
22- size = <N>;
19+ this.size = s.Length;
20+ if (this.size > <N>){
21+ throw new NotSupportedException(
22+ "Cannot create a char<N> object with more than <N> characters"
23+ );
2324 }
24- Array.Copy(buffer , 0, bytes, 0, size );
25+ System.Text.Encoding.ASCII.GetBytes(s , 0, this.size, this.bytes, 0 );
2526 }
2627
2728 public string GetString(){
@@ -40,13 +41,14 @@ public struct char64 {
4041 private byte [ ] bytes ;
4142
4243 public char64 ( string s ) {
43- var buffer = System . Text . Encoding . ASCII . GetBytes ( s ) ;
44- this . size = buffer . Length ;
4544 this . bytes = new byte [ 64 ] ;
46- if ( size > 64 ) {
47- size = 64 ;
45+ this . size = s . Length ;
46+ if ( this . size > 64 ) {
47+ throw new NotSupportedException (
48+ "Cannot create a char64 object with more than 64 characters"
49+ ) ;
4850 }
49- Array . Copy ( buffer , 0 , bytes , 0 , size ) ;
51+ System . Text . Encoding . ASCII . GetBytes ( s , 0 , this . size , this . bytes , 0 ) ;
5052 }
5153
5254 public string GetString ( ) {
@@ -62,13 +64,14 @@ public struct char256 {
6264 private byte [ ] bytes ;
6365
6466 public char256 ( string s ) {
65- var buffer = System . Text . Encoding . ASCII . GetBytes ( s ) ;
66- this . size = buffer . Length ;
6767 this . bytes = new byte [ 256 ] ;
68- if ( size > 256 ) {
69- size = 256 ;
68+ this . size = s . Length ;
69+ if ( this . size > 256 ) {
70+ throw new NotSupportedException (
71+ "Cannot create a char256 object with more than 256 characters"
72+ ) ;
7073 }
71- Array . Copy ( buffer , 0 , bytes , 0 , size ) ;
74+ System . Text . Encoding . ASCII . GetBytes ( s , 0 , this . size , this . bytes , 0 ) ;
7275 }
7376
7477 public string GetString ( ) {
0 commit comments