Class: Ucp::Util::UCP

Inherits:
Object
  • Object
show all
Defined in:
lib/ucp/util/ucp.rb

Class Method Summary collapse

Class Method Details

.add_char(value, char) ⇒ Object



36
37
38
39
# File 'lib/ucp/util/ucp.rb', line 36

def self.add_char(value,char)
  @gsmtable[char]=value
  @asciitable[value]=char
end

.add_extchar(value, char) ⇒ Object



42
43
44
45
# File 'lib/ucp/util/ucp.rb', line 42

def self.add_extchar(value,char)
  @extensiontable[char]=value
  @extensiontable_rev[value]=char
end

.ascii2ira(str, max_bytes = nil) ⇒ Object

convert standard string to IRA encoded hexstring



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/ucp/util/ucp.rb', line 281

def self.ascii2ira(str,max_bytes=nil)

  tainted=false  # true if not able to convert a character
  s=""
  idx=0
  str.each_char  { |c|
    gsmchar=@gsmtable[c]

    ext=""
    if gsmchar.nil?
      if @extensiontable.has_key?(c)
        ext="1B"
        gsmchar=@extensiontable[c]
      else
        gsmchar=@gsmtable[" "]
        tainted=true
      end
    end


    tmp=int2hex(gsmchar)


    if !max_bytes.nil?
      # if adding this character exceeds the max allowed nr of bytes, break
      if ((tmp+ext+s).length*7.0/16).ceil>max_bytes
        break
      end
    end

    s+=ext+tmp
    idx+=(ext+tmp).length/2

    # if reached the max allowed nr of bytes, break
    #    if (s.length*7.0/16).floor==max_bytes
    #      break
    #    end

  }

  required_septets=s.length/2
  #puts "idx: #{idx}; req_sep: #{required_septets}"
  return GsmPackedMsg.new(s,UCP.utf8_substr(str,0,idx-1),idx,required_septets,tainted)
end

.decode7bitgsm(str) ⇒ Object



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/ucp/util/ucp.rb', line 532

def self.decode7bitgsm(str)
  
  # retirar isto!!
  #initialize_ascii2ira
  
  unencoded=""
  #puts "#{str}"
  bstr=UCP.hextobin_reversed(str)
  #puts "#{bstr}"
  # 110 1111 110 1100 110 0001
  # 1000011 1011101 0110111   000

  i=bstr.length-7
  while i>=0
    value=bstr[i,7].to_i(2)
    if value==0x1B
      i-=7
      value=@extensiontable_rev[bstr[i,7].to_i(2)]
      value=" " if value.nil?
      unencoded+=value
    else
      val=@asciitable[value]
      #puts "value: #{value} ; val: #{val}"
      val=" " if val.nil?
      unencoded+=val
      #unencoded+=value.chr
    end


    

    i-=7
  end


  #    i=0
  #    while i<str.length
  #      hexv=str[i,2]
  #      if "1B".eql?(hexv)
  #        i+=2
  #        hexv=str[i,2]
  #      end
  #
  #      unencoded+=hexv.to_i(16).chr
  #
  #      i+=2
  #    end


  return unencoded
end

.decode_ira(str) ⇒ Object



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
# File 'lib/ucp/util/ucp.rb', line 586

def self.decode_ira(str)
  unencoded=""

  i=0
  while i<str.length
    hexv=str[i,2]
    if "1B".eql?(hexv)
      i+=2
      hexv=str[i,2]

      value=@extensiontable_rev[hexv.to_i(16)]
      value=" " if value.nil?
      unencoded+=value
    else
      val=@asciitable[hexv.to_i(16)]
      val=" " if val.nil?
      unencoded+=val
    end

    i+=2
  end

  return unencoded
end

.decode_ucp_msg(ucp) ⇒ Object



820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
# File 'lib/ucp/util/ucp.rb', line 820

def self.decode_ucp_msg(ucp)
  text=nil
  dcs=ucp.dcs.to_i(16)

  if (dcs & 0x0F == 0x01) || (dcs & 0x0F == 0x00)

    if ucp.operation.eql?("30")
      text=UCP.decode_ira(ucp.get_field(:amsg))
    else

      if ucp.operation.eql?("51") || ucp.operation.eql?("52") || ucp.operation.eql?("53")
        mt=ucp.get_field(:msg)
        if mt.eql?("2")
          # numeric message.. return it as it is
          text=ucp.get_field(:msg)
        elsif mt.eql?("3")
          text=UCP.decode_ira(ucp.get_field(:msg))
        else
          # unexpected "mt" value. return nil explicitely
          return nil
        end
      elsif ucp.operation.eql?("01")
        text=UCP.decode_ira(ucp.get_field(:msg))
      else
        # unexpected operation. return nil explicitely
        return nil
      end

    end
  elsif (dcs & 0x0F == 0x08) || (dcs & 0x0F == 0x09)
    str=UCP.hex2str(ucp.get_field(:msg))
    text=Iconv.iconv("utf-8","utf-16be",str).first
  else
    # cant decode text; unsupported DCS
    return nil
  end

  return text
end

.decode_ucp_oadc(ucp) ⇒ Object



860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
# File 'lib/ucp/util/ucp.rb', line 860

def self.decode_ucp_oadc(ucp)
  otoa=nil
  oadc=ucp.get_field(:oadc)

  if ucp.is_a?(Ucp51Operation) || ucp.is_a?(Ucp52Operation) || ucp.is_a?(Ucp53Operation) || ucp.is_a?(Ucp54Operation) || ucp.is_a?(Ucp55Operation) || ucp.is_a?(Ucp56Operation) || ucp.is_a?(Ucp57Operation) || ucp.is_a?(Ucp58Operation)
    otoa=ucp.get_field(:otoa)
  end

  if otoa.nil? || otoa.eql?("1139")
    return oadc
  elsif otoa.eql?("5039")
    #useful_nibbles=oadc[0,2].to_i(16)
    return UCP.decode7bitgsm(oadc[2..-1])
  else
    #
  end

  # by default, return oadc
  return oadc
end

.hex2str(hexstr) ⇒ Object



814
815
816
817
818
# File 'lib/ucp/util/ucp.rb', line 814

def self.hex2str(hexstr)
  str=""
  hexstr.scan(/../).each { | tuple | str+=tuple.hex.chr }
  return str
end

.hextobin(hstr) ⇒ Object



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/ucp/util/ucp.rb', line 496

def self.hextobin(hstr)
  bstr=""
  i=0
  while i<hstr.length
    tmp=hstr[i,2].to_i(16).to_s(2)

    nfillbits=8-tmp.length
    if nfillbits!=0
      tmp="0"*nfillbits+tmp
    end

    bstr+=tmp
    i+=2
  end
  return bstr
end

.hextobin_reversed(hstr) ⇒ Object



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/ucp/util/ucp.rb', line 514

def self.hextobin_reversed(hstr)
  bstr=""
  i=0
  while i<hstr.length
    tmp=hstr[i,2].to_i(16).to_s(2)

    nfillbits=8-tmp.length
    if nfillbits!=0
      tmp="0"*nfillbits+tmp
    end

    bstr=tmp+bstr
    i+=2
  end
  return bstr
end

.initialize_ascii2iraObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ucp/util/ucp.rb', line 47

def self.initialize_ascii2ira
  
  ('A'..'Z').each { |c|
    add_char(c[0],c)
  }
  ('a'..'z').each { |c|
    #@gsmtable[c]=c[0]
    #@asciitable[c[0]]=c
    add_char(c[0],c)
  }
  ('0'..'9').each { |c|
    add_char(c[0],c)
  }


  add_char(0x00,"@")
  add_char(0x01,"£")
  add_char(0x02,"$")
  #add_char(0x03," ")
  add_char(0x04,"è")
  add_char(0x05,"é")
  add_char(0x06,"ù")
  add_char(0x07,"ì")
  add_char(0x08,"ò")
  add_char(0x09,"Ç")
  add_char(0x0A,"\n")
  #add_char(0x0B," ")
  #add_char(0x0C," ")
  add_char(0x0D,"\r")
  #add_char(0x0E,"A")
  #add_char(0x0F,"a")

  add_char(0x1F,"É")



  add_char(0x20," ")
  add_char(0x21,"!")
  add_char(0x22,'"')
  add_char(0x23,"#")
  #add_char(0x24," ")
  add_char(0x25,"%")
  add_char(0x26,"&")
  add_char(0x27,"'")
  add_char(0x28,"(")
  add_char(0x29,")")
  add_char(0x2A,"*")
  add_char(0x2B,"+")
  add_char(0x2C,",")
  add_char(0x2D,"-")
  add_char(0x2E,".")
  add_char(0x2F,"/")

  add_char(0x3A,":")
  add_char(0x3B,";")
  add_char(0x3C,"<")
  add_char(0x3D,"=")
  add_char(0x3E,">")
  add_char(0x3F,"?")



  #@extensiontable["€"]=0x65
  #@extensiontable_rev[0x65]="€"
  add_extchar(0x65,"")
  add_extchar(0x14,"^")
  add_extchar(0x28,"{")
  add_extchar(0x29,"}")
  add_extchar(0x2F,"\\")
  add_extchar(0x3C,"[")
  add_extchar(0x3D,"~")
  add_extchar(0x3E,"]")
  add_extchar(0x40,"|")



end

.int2hex(i, max_nibbles = 2) ⇒ Object



614
615
616
617
618
619
620
621
622
623
624
625
626
# File 'lib/ucp/util/ucp.rb', line 614

def self.int2hex(i,max_nibbles=2)
  tmp=i.to_s(16).upcase
  if tmp.length%2!=0
    tmp="0"+tmp
  end

  remaining_nibbles=max_nibbles-tmp.length
  if remaining_nibbles>0
    tmp="0"*remaining_nibbles+tmp;
  end

  return tmp
end

.make_multi_ucps(originator, recipient, message, mr = 0) ⇒ Object



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/ucp/util/ucp.rb', line 420

def self.make_multi_ucps(originator,recipient,message,mr=0)
  ucps=[]

  gsm7bit_encodable=false

  if gsm7bit_encodable
    gsmparts= UCP.multi_ascii2ira(message,134)
  else
    gsmparts= UCP.multi_ucs2(message,134)
  end


  part_nr=1
  gsmparts.each { |gsmpart|
    ucp=Ucp51Operation.new
    ucp.basic_submit(originator,recipient,nil)

    if gsmparts.length>1
      # concatenated xser
      ucp.add_xser("01","050003"+UCP.int2hex(mr)+UCP.int2hex(gsmparts.length)+UCP.int2hex(part_nr))
    end

    if gsm7bit_encodable
      ucp.set_fields({:mt=>3, :msg=>gsmpart.encoded})
      # DCS xser
      ucp.add_xser("02","01")
    else
      ucp.set_fields({:msg=>gsmpart.encoded,:mt=>4,:nb=>gsmpart.encoded.length*4})
      # DCS xser
      ucp.add_xser("02","08")
    end

    #ucp.trn=UCP.int2hex(initial_trn)
    #initial_trn+=1

    #puts "part: #{ucp.to_s}"
    ucps<<ucp
    part_nr+=1
  }
  return ucps
end

.make_ucp_result(ucp) ⇒ Object

usado para construir uma resposta UCP a partir dum UCP



763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
# File 'lib/ucp/util/ucp.rb', line 763

def self.make_ucp_result(ucp)
  puts "make_ucp_result(#{ucp.to_s})"

  if ucp.nil?
    return nil
  end

  trn=ucp.trn
  #puts "#{trn}"
  # length
  operation_type=ucp.operation_type
  #puts "#{operation_type}"
  operation=ucp.operation
  #puts "#{operation}"

  ucpmsg=nil

  if operation.eql?("01")
    ucpmsg=Ucp01Result.new
  elsif operation.eql?("30")
    ucpmsg=Ucp30Result.new
  elsif operation.eql?("31")
    ucpmsg=Ucp31Result.new
  elsif operation.eql?("51")
    ucpmsg=Ucp51Result.new
  elsif operation.eql?("52")
    ucpmsg=Ucp52Result.new
  elsif operation.eql?("53")
    ucpmsg=Ucp53Result.new
  elsif operation.eql?("54")
    ucpmsg=Ucp54Result.new
  elsif operation.eql?("55")
    ucpmsg=Ucp55Result.new
  elsif operation.eql?("56")
    ucpmsg=Ucp56Result.new
  elsif operation.eql?("57")
    ucpmsg=Ucp57Result.new
  elsif operation.eql?("58")
    ucpmsg=Ucp58Result.new
  elsif operation.eql?("60")
    ucpmsg=Ucp60Result.new
  elsif operation.eql?("61")
    ucpmsg=Ucp61Result.new
  else
    return nil
  end

  ucpmsg.trn=trn
  return ucpmsg
end

.multi_ascii2ira(str, max_bytes) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/ucp/util/ucp.rb', line 338

def self.multi_ascii2ira(str,max_bytes)
  msgparts=[]
  idx=0

  if str.jlength<=160
    packedmsg=UCP.ascii2ira(UCP.utf8_substr(str,idx),140)
    #puts "pckd_chars: #{packedmsg.chars}; strlen: #{str.jlength}"
    if packedmsg.chars==str.jlength
      msgparts<<packedmsg
      return msgparts
    end
  end

  while true
    #packedmsg=UCP.ascii2ira(str[idx..-1],max_bytes)
    #puts "bla: #{UCP.utf8_substr(str,idx)}"
    packedmsg=UCP.ascii2ira(UCP.utf8_substr(str,idx),max_bytes)
    msgparts<<packedmsg
    #break
    #puts "idx: #{idx}; pckd_chars: #{packedmsg.chars}; strlen: #{str.jlength}"
    
    #puts "sL: #{UCP.utf8_substr(str,idx,idx+packedmsg.chars- 1)} ; #{str[0,idx+packedmsg.chars].length}#"

    #if idx+packedmsg.chars<str.length
    if idx+packedmsg.chars<str.jlength
      idx+=packedmsg.chars
    else
      break
    end
  end
  return msgparts
end

.multi_pack7bits(str, max_bytes) ⇒ Object

Deprecated.

remove because unecessary



264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/ucp/util/ucp.rb', line 264

def self.multi_pack7bits(str,max_bytes)
  msgparts=[]
  idx=0
  while true
    packedmsg=UCP.pack7bits2(str[idx..-1],max_bytes)
    msgparts<<packedmsg
    if idx+packedmsg.chars<str.length
      idx+=packedmsg.chars
    else
      break
    end
  end
  return msgparts
end

.multi_ucs2(str, max_bytes) ⇒ Object



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/ucp/util/ucp.rb', line 387

def self.multi_ucs2(str,max_bytes)
  msgparts=[]
  idx=0

  if str.jlength<=70
    packedmsg=UCP.str2ucs2(str,140)
    #puts "pckd_chars: #{packedmsg.chars}; strlen: #{str.jlength}"
    if packedmsg.chars==str.jlength
      msgparts<<packedmsg
      return msgparts
    end
  end

  while true

    #puts "bla: #{UCP.utf8_substr(str,idx)}"
    packedmsg=UCP.str2ucs2(UCP.utf8_substr(str,idx),max_bytes)
    msgparts<<packedmsg
    #break
    #puts "idx: #{idx}; pckd_chars: #{packedmsg.chars}; strlen: #{str.jlength}"
    #puts "sL: #{UCP.utf8_substr(str,idx,idx+packedmsg.chars- 1)} ; #{str[0,idx+packedmsg.chars].length}#"

    if idx+packedmsg.chars<str.jlength
      idx+=packedmsg.chars
    else
      break
    end
  end
  return msgparts
end

.pack7bits(str) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/ucp/util/ucp.rb', line 125

def self.pack7bits(str)
  #UCP.initialize_ascii2ira
  
  s=""
  str.each_char  { |c|

    ext=""
    gsmchar=@gsmtable[c]

    if gsmchar.nil?
      if @extensiontable.has_key?(c)
        ext="0011011" # 1B
        gsmchar=@extensiontable[c]
      else
        gsmchar=@gsmtable[" "]
      end
    end

    #gsmchar=c[0]
    #puts "#{c} : #{gsmchar} xxx"
    #gsmchar=@gsmtable[" "] if gsmchar.nil?
    
    tmp= gsmchar.to_s(2)

    remainder=tmp.length%7
    if remainder!=0
      nfillbits=7-remainder
      tmp="0"*nfillbits+tmp
    end
    
    s=tmp+ext+s

  }

  remainder=s.length%8
  if remainder!=0
    nfillbits=8-remainder
    s="0"*nfillbits+s
  end

  #puts "S: #{s}"
  
  i=s.length-8
  hexstr=""
  while i>=0
    c=s[i,8]

    tmp=c.to_i(2).to_s(16).upcase
    if tmp.length==1
      tmp="0"+tmp
    end
    #      puts tmp
    hexstr+=tmp
    i-=8
  end

  

  return hexstr
end

.pack7bits2(str, max_bytes) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/ucp/util/ucp.rb', line 187

def self.pack7bits2(str,max_bytes)

  tainted=false
  s=""
  idx=0
  str.each_char  { |c|

    ext=""
    gsmchar=@gsmtable[c]

    if gsmchar.nil?
      if @extensiontable.has_key?(c)
        ext="0011011" # 1B
        gsmchar=@extensiontable[c]
      else
        gsmchar=@gsmtable[" "]
        tainted=true
      end
    end

    #gsmchar=c[0]
    #puts "#{c} : #{gsmchar} xxx"
    #gsmchar=@gsmtable[" "] if gsmchar.nil?

    tmp= gsmchar.to_s(2)

    remainder=tmp.length%7
    if remainder!=0
      nfillbits=7-remainder
      tmp="0"*nfillbits+tmp
    end

    # if adding this character exceeds the max allowed nr of bytes, break
    if ((tmp+ext+s).length*1.0/8).ceil>max_bytes
      break
    end

    s=tmp+ext+s

    # if reached the max allowed nr of bytes, break
    if (s.length*1.0/8).ceil==max_bytes
      idx+=1
      break
    end
    
    idx+=1
  }


  required_septets=s.length/7
  remainder=s.length%8
  if remainder!=0
    nfillbits=8-remainder
    s="0"*nfillbits+s
  end

  #puts "S: #{s}"

  i=s.length-8
  hexstr=""
  while i>=0
    c=s[i,8]

    tmp=c.to_i(2).to_s(16).upcase
    if tmp.length==1
      tmp="0"+tmp
    end
    #      puts tmp
    hexstr+=tmp
    i-=8
  end


  return GsmPackedMsg.new(hexstr,str[0,idx],idx,required_septets,tainted)
end

.packoadc(oa) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/ucp/util/ucp.rb', line 481

def self.packoadc(oa)
  packedoa=UCP.pack7bits(oa)

  # esta conta nao esta correcta... por causa das extensoes...
  #useful_nibbles=packedoa.length
  useful_nibbles=(oa.length*7.0/4).ceil

  tmp=useful_nibbles.to_s(16).upcase
  if tmp.length==1
    tmp="0"+tmp
  end

  return tmp+packedoa
end

.packucs2(str) ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/ucp/util/ucp.rb', line 464

def self.packucs2(str)
  hexstr=""
  s= Iconv.iconv("ucs-2be", "utf-8", str).first
  s.each_char{ |c|

    tmp=c[0].to_s(16).upcase
    if tmp.length==1
      tmp="0"+tmp
    end

    hexstr+=tmp

  }
  #puts s
  return hexstr
end

.parse_str(ustr) ⇒ Object

usado para construir um UCP duma string



631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'lib/ucp/util/ucp.rb', line 631

def self.parse_str(ustr)
  #puts "parse_str(#{ustr})"

  if ustr.nil?
    return nil
  end

  arr=ustr[(ustr.index(2.chr)+1)..-2].split("/")
  trn=arr[0]
  #puts "#{trn}"
  # length
  operation_type=arr[2]
  #puts "#{operation_type}"
  operation=arr[3]
  #puts "#{operation}"

  ucpmsg=nil

  if operation.eql?("01")
    if operation_type.eql?("O")
      # puts "parsing a ucp01"
      ucpmsg=Ucp01Operation.new(arr)
    elsif operation_type.eql?("R")
      # puts "parsing a result of a  ucp01"
      ucpmsg=Ucp01Result.new(arr)        
    end
  elsif operation.eql?("30")
    if operation_type.eql?("O")
      # puts "parsing a ucp30"
      ucpmsg=Ucp30Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp30"
      ucpmsg=Ucp30Result.new(arr)
    end
  elsif operation.eql?("31")
    if operation_type.eql?("O")
      #puts "parsing a ucp31"
      ucpmsg=Ucp31Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp31"
      ucpmsg=Ucp31Result.new(arr)
    end
  elsif operation.eql?("51")
    if operation_type.eql?("O")
      #puts "parsing a ucp51"
      ucpmsg=Ucp51Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp51"
      ucpmsg=Ucp51Result.new(arr)
    end
  elsif operation.eql?("52")
    if operation_type.eql?("O")
      #puts "parsing a ucp52"
      ucpmsg=Ucp52Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp52"
      ucpmsg=Ucp52Result.new(arr)
    end
  elsif operation.eql?("53")
    if operation_type.eql?("O")
      #puts "parsing a ucp53"
      ucpmsg=Ucp53Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp53"
      ucpmsg=Ucp53Result.new(arr)
    end
  elsif operation.eql?("54")
    if operation_type.eql?("O")
      #puts "parsing a ucp54"
      ucpmsg=Ucp54Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp54"
      ucpmsg=Ucp54Result.new(arr)
    end
  elsif operation.eql?("55")
    if operation_type.eql?("O")
      #puts "parsing a ucp55"
      ucpmsg=Ucp55Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp55"
      ucpmsg=Ucp55Result.new(arr)
    end
  elsif operation.eql?("56")
    if operation_type.eql?("O")
      #puts "parsing a ucp56"
      ucpmsg=Ucp56Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp56"
      ucpmsg=Ucp56Result.new(arr)
    end
  elsif operation.eql?("57")
    if operation_type.eql?("O")
      #puts "parsing a ucp57"
      ucpmsg=Ucp57Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp57"
      ucpmsg=Ucp57Result.new(arr)
    end
  elsif operation.eql?("58")
    if operation_type.eql?("O")
      #puts "parsing a ucp58"
      ucpmsg=Ucp58Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp58"
      ucpmsg=Ucp58Result.new(arr)
    end
  elsif operation.eql?("60")
    if operation_type.eql?("O")
      #puts "parsing a ucp60"
      ucpmsg=Ucp60Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp60"
      ucpmsg=Ucp60Result.new(arr)
    end
  elsif operation.eql?("61")
    if operation_type.eql?("O")
      #puts "parsing a ucp61"
      ucpmsg=Ucp61Operation.new(arr)
    elsif operation_type.eql?("R")
      #puts "parsing a result of a  ucp61"
      ucpmsg=Ucp61Result.new(arr)
    end
  end

  #ucpmsg.trn=trn
  return ucpmsg
end

.str2ucs2(str, max_bytes = nil) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/ucp/util/ucp.rb', line 372

def self.str2ucs2(str,max_bytes=nil)
  hexstr=""
  str=Iconv.iconv("utf-16be", "utf-8", str).first
  i=0
  str.each_byte{ |c|
    hexstr+=UCP.int2hex(c)
    i+=1
    if (!max_bytes.nil?) && (i == max_bytes)
      break
    end
  }

  return Ucs2PackedMsg.new(hexstr,UCP.utf8_substr(str,0,i-1),i/2,i)
end

.utf8_substr(str, idxs, idxe = nil) ⇒ Object



327
328
329
330
331
332
333
334
335
336
# File 'lib/ucp/util/ucp.rb', line 327

def self.utf8_substr(str,idxs,idxe=nil)
  s=""
  i=0
  idxe=str.jlength-1 if idxe.nil?
  str.each_char{ |c|
    s+=c if i>=idxs and i<=idxe
    i+=1
  }
  return s
end