FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor


 
 
LinkBack Thread Tools
 
Old 06-30-2010, 09:47 PM
Victor Lowther
 
Default Simplify in_array.

All that extra checking for the first character being @ is not needed,
simple parameter expansion will trim it off if it is there.
---
functions | 18 +++++++-----------
1 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/functions b/functions
index 9d0aec3..8bbdfc6 100644
--- a/functions
+++ b/functions
@@ -136,17 +136,13 @@ status() {
# 1 - not found
# Copied from makepkg
in_array() {
- local needle=$1; shift
- [ -z "$1" ] && return 1 # Not Found
- local item
- for item in "$@"; do
- local c="${item:0:1}"
- if [ "x$c" = "x@" ]; then
- item="${item:1}"
- fi
- [ "$item" = "$needle" ] && return 0 # Found
- done
- return 1 # Not Found
+ [[ $2 ]] || return 1
+ local needle=$1; shift
+ local item
+ for item in "$@"; do
+ [[ ${item#@} = $needle ]] && return 0
+ done
+ return 1 # Not Found
}

# daemons:
--
1.7.1
 

Thread Tools




All times are GMT. The time now is 07:11 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org