Advertisement
Linda-chan

OptimizeRussianText.VBS

Jun 15th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Const fbAuto = 0
  4. Const fbNoBOM = 1
  5. Const fbBOM = 2
  6.  
  7. Const feAuto = 0
  8. Const feANSI = 1
  9. Const feUTF8 = 2
  10. Const feUTF16 = 3
  11.  
  12. Const ibAuto = 0
  13. Const ibDontInvertBytes = 1
  14. Const ibInvertBytes = 2
  15.  
  16. Dim ajpFSO
  17. Set ajpFSO = CreateObject("FileIOSupport0102.ajpFSO")
  18.  
  19. '====================================================================
  20. Dim InFileName
  21. Dim OutFileName
  22.  
  23. Select Case WScript.Arguments.Count
  24.   Case 1
  25.     InFileName = WScript.Arguments(0)
  26.     OutFileName = ""
  27.   Case 2
  28.     InFileName = WScript.Arguments(0)
  29.     OutFileName = WScript.Arguments(1)
  30.   Case Else
  31.     WScript.Echo "Uage: OptimizeRussianText[.VBS] InputFileName [OutputFileName]"
  32.     WScript.Quit
  33. End Select
  34.  
  35. '====================================================================
  36. Dim TXT
  37.  
  38. On Error Resume Next
  39.  
  40. TXT = ajpFSO.GetFile2(InFileName, True)
  41. If Err.Number <> 0 Then
  42.   WScript.Echo "Can't read file. Error " & Err.Number & ": " & Err.Description
  43.   WScript.Quit
  44. End If
  45.  
  46. '====================================================================
  47. Dim Chars
  48. Dim TMP
  49.  
  50. Chars = Array("Ё", "Е", "Й", "И", "Щ", "Ш", "Л", "П", _
  51.               "Ы", "Ь", "Б", "Ь", "В", "Ь", "Ю", "О", _
  52.               "Ъ", "Ь", "Н", "Ч", "П", "Г")
  53.  
  54. For TMP = LBound(Chars) To UBound(Chars) - 1 Step 2
  55.   TXT = Replace(TXT, UCase(Chars(TMP)), UCase(Chars(TMP + 1)), vbTextCompare)
  56.   TXT = Replace(TXT, LCase(Chars(TMP)), LCase(Chars(TMP + 1)), vbTextCompare)
  57. Next
  58.  
  59. '====================================================================
  60. If OutFileName = "" Then
  61.   WScript.Echo TXT
  62.   WScript.Quit
  63. End If
  64.  
  65. '====================================================================
  66. ajpFSO.PutFile2 OutFileName, TXT, True, feUTF8, fbBOM
  67. If Err.Number <> 0 Then
  68.   WScript.Echo "Can't write file. Error " & Err.Number & ": " & Err.Description
  69.   WScript.Quit
  70. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement