You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/02/17 02:59:54 UTC
[lucy-commits] svn commit: r1071476 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/DocuComment.pm src/CFCDocuComment.c src/CFCDocuComment.h
Author: marvin
Date: Thu Feb 17 01:59:53 2011
New Revision: 1071476
URL: http://svn.apache.org/viewvc?rev=1071476&view=rev
Log:
Port code for stripping C comment detritus in DocuComments from Perl to C.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.pm
incubator/lucy/trunk/clownfish/src/CFCDocuComment.c
incubator/lucy/trunk/clownfish/src/CFCDocuComment.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1071476&r1=1071475&r2=1071476&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Feb 17 01:59:53 2011
@@ -179,6 +179,17 @@ PPCODE:
END_SET_OR_GET_SWITCH
}
+SV*
+strip(text)
+ SV *text;
+CODE:
+ RETVAL = newSVsv(text);
+ STRLEN len;
+ char *ptr = SvPV(RETVAL, len);
+ CFCDocuComment_strip(ptr);
+ SvCUR_set(RETVAL, strlen(ptr));
+OUTPUT: RETVAL
+
MODULE = Clownfish PACKAGE = Clownfish::File
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.pm?rev=1071476&r1=1071475&r2=1071476&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.pm Thu Feb 17 01:59:53 2011
@@ -33,9 +33,9 @@ sub parse {
my $class_name = ref($either) || $either;
# Strip comment open, close, and left border.
- $text =~ s/\A\s*\/\*\*\s+//;
- $text =~ s/\s+\*\/\s*\Z//;
- $text =~ s/^\s*\* ?//gm;
+ $text =~ s/^\s*//;
+ $text =~ s/\s*$//;
+ $text = strip($text);
# Extract the brief description.
$text =~ /^(.+?\.)(\s+|\Z)/s
Modified: incubator/lucy/trunk/clownfish/src/CFCDocuComment.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCDocuComment.c?rev=1071476&r1=1071475&r2=1071476&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCDocuComment.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCDocuComment.c Thu Feb 17 01:59:53 2011
@@ -15,6 +15,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
@@ -30,6 +31,56 @@ struct CFCDocuComment {
const char *retval;
};
+void
+CFCDocuComment_strip(char *comment)
+{
+ size_t len = strlen(comment);
+ char *scratch = (char*)malloc(len + 1);
+ if (!scratch) {
+ croak("malloc failed");
+ }
+
+ // Establish that comment text begins with "/**" and ends with "*/".
+ if ( strstr(comment, "/**") != comment
+ || strstr(comment, "*/") != (comment + len - 2)
+ ) {
+ croak("Malformed comment");
+ }
+
+ // Capture text minus beginning "/**", ending "*/", and left border.
+ size_t i = 3;
+ size_t max = len - 2;
+ while ((isspace(comment[i]) || comment[i] == '*') && i < max) {
+ i++;
+ }
+ size_t j = 0;
+ for ( ; i < max; i++) {
+ while (comment[i] == '\n' && i < max) {
+ scratch[j++] = comment[i];
+ i++;
+ while (isspace(comment[i]) && comment[i] != '\n' && i < max) {
+ i++;
+ }
+ if (comment[i] == '*') { i++; }
+ while (isspace(comment[i]) && comment[i] != '\n' && i < max) {
+ i++;
+ }
+ }
+ if (i < max) {
+ scratch[j++] = comment[i];
+ }
+ }
+
+ // Modify original string in place.
+ for (i = 0; i < j; i++) {
+ comment[i] = scratch[i];
+ }
+ comment[j] = '\0';
+
+ // Clean up.
+ free(scratch);
+}
+
CFCDocuComment*
CFCDocuComment_new(const char *description, const char *brief,
const char *long_description, void *param_names,
Modified: incubator/lucy/trunk/clownfish/src/CFCDocuComment.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCDocuComment.h?rev=1071476&r1=1071475&r2=1071476&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCDocuComment.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCDocuComment.h Thu Feb 17 01:59:53 2011
@@ -16,6 +16,11 @@
typedef struct CFCDocuComment CFCDocuComment;
+/** Remove comment open, close, and left border from raw comment text.
+ */
+void
+CFCDocuComment_strip(char *comment);
+
CFCDocuComment*
CFCDocuComment_new(const char *description, const char *brief,
const char *long_description, void *param_names,