Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th August 2011, 11:24   #1  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
New Script: FindStrClass

This is like FindStr but finds a class of character, like the first number, letter, symbol or specially defined character.
Code:
#FindStrClass Ver 0.9 by jmac698
#A Script Function to find the next number, letter, symbol, etc.

s="x 0"
r1=FindStrClass(s,4,"")
r2=FindStrClass(s,2,"")
r3=FindStrClass(s,3,"")
msg="With '"+s+"' the first letter at "+string(r1)+" first number at "+string(r2)+" first symbol or number at "+string(r3)
return messageclip(msg)

function FindStrClass(string base, int classmask, string special){
  #Return position of specified character class
  #symbol=1, number=2, letter=4, special=8, null=0
  #these can be combined for classmask, 
  #e.g. maskclass=14 is special or letter or number
  FindStrClass2(base, classmask, special, 1)
}

function FindStrClass2(string base, int classmask, string special, int currpos){
  substr=midstr(base,currpos,1)
  t=binbool(strClassify(substr, special),classmask,"and")!=0 || currpos==strlen(base)+1
  t ? currpos : \
  FindStrClass2(base, classmask, special, currpos+1)
}

function binbool(int a, int b, string op){
  #Find the binary AND or OR on a and b
  op=lcase(op)
  op=op=="or"?"||" : \
  op=="and"?"&&" : \
  strlen(op)==1?op+op:op
  binbool2(a, b, op, 0)
}

function binbool2(int a, int b, string op, int currresult){
  m=max(a,b)
  pwr2=int(pow(2,floor(log(m)/log(2))))
  bit_a=floor(a/pwr2)
  bit_b=floor(b/pwr2)
  t=eval(string(bool(bit_a))+op+string(bool(bit_b)))?pwr2:0
  currresult=currresult+t
  a=a-bit_a*pwr2
  b=b-bit_b*pwr2
  a+b==0?currresult:binbool2(a, b, op, currresult)
}

function bool(int n){
  #Return false if n=0, true otherwise
  n==0?false:true
}

function strClassify(string s, string special){
  #Classify a character as symbol (1), number (2), letter (4), special (8) or null (0)
  s=leftstr(s,1)
  s=="" ? 0  : \
  s==special ? 8 : \
  (s>="a" && s<="z") || (s>="A" && s<="Z") ? 4 : \
  s>="0" && s<="9" ? 2 : \
  1
}
jmac698 is offline   Reply With Quote
Old 24th August 2011, 22:22   #2  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,049
Why is this thread and the binary maths one in the Avisynth development forum?
TheFluff is offline   Reply With Quote
Old 24th August 2011, 23:59   #3  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
Because it's about plugin and script development? It's certainly not about usage. This is the programmers forum isn't it?
jmac698 is offline   Reply With Quote
Old 25th August 2011, 10:13   #4  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,049
Quote:
Originally Posted by jmac698 View Post
Because it's about plugin and script development? It's certainly not about usage. This is the programmers forum isn't it?
Your scripting is Avisynth usage; it's not development of either a plugin or the Avisynth core. Therefore it goes in the Avisynth usage forum, IMO. Furthermore I'd say you should keep all of your small utils in one thread since you seem to be posting new ones every week and most of them aren't getting very many comments.
TheFluff is offline   Reply With Quote
Old 25th August 2011, 19:57   #5  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
That's a great idea, I should make a jmac_utils package and keep adding to it. There is something similar in the jd_utils. I find posting publicly useful for me as I find my own work easier on the web than my own harddrive I've also made some major scripts like vcr simulator or glitch analyzer, these are not in the same vein as short util functions.

It's up the mods to move it, not sure I have power to do this unless I delete everything and repost, but the comments would still be there? I don't think users can delete an entire thread.
jmac698 is offline   Reply With Quote
Old 25th August 2011, 22:49   #6  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,049
Quote:
Originally Posted by jmac698 View Post
That's a great idea, I should make a jmac_utils package and keep adding to it. There is something similar in the jd_utils. I find posting publicly useful for me as I find my own work easier on the web than my own harddrive I've also made some major scripts like vcr simulator or glitch analyzer, these are not in the same vein as short util functions.

It's up the mods to move it, not sure I have power to do this unless I delete everything and repost, but the comments would still be there? I don't think users can delete an entire thread.
Yes, of course bigger/more interesting scripts should have their own threads, but for small utils like these a single thread would be better, IMO.
TheFluff is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:52.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.